[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Easy question how to get a value of a dropdownlist user control.

Posted on 2009-05-01
17
Medium Priority
?
320 Views
Last Modified: 2012-05-06
I created the following:
<add tagPrefix="KORE" tagName="uxLookupFieldTicketStatus" src="~/Controls/Lookup/uxLookupFieldTicketStatus.ascx" />
            
in my web config.

I want to access the dropdownlist value. and assign it.
protected void btnSaveExit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // Instantiate business object
                BLL.Tickets tickets = new BLL.Tickets();
                tickets.TicketType = ???

            }
        }

where the
<td class="TicketLabel"><asp:Label ID="lblType" runat="server" Text="Type:" Font-Bold="True"></asp:Label></td>
                                        <td class="TicketLabel">
                                        <KORE:uxLookupFieldTicketType runat="server" ID="uxLookupFieldTicketType1"
                                    KeyField="TicketType" ValueField="ID" />
                                    </td>                  

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="uxLookupFieldTicketStatus.ascx.cs" Inherits="KORE.SIDWebClient.UI.Controls.uxLookupFieldTicketStatus" %>
 
<asp:DropDownList ID="LookupFieldTicketStatusDropDown" AppendDataBoundItems="true" Width="200px" runat="server">
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownList><br />
<asp:RequiredFieldValidator id="CVLookupFieldTicketStatusDropDown"
        Text="(Required)"
        InitialValue=""
        ControlToValidate="LookupFieldTicketStatusDropDown"
        Runat="server" />
====================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KORE.SIDWebClient.BLL;
using System.ComponentModel;
 
namespace KORE.SIDWebClient.UI.Controls
{
    public partial class uxLookupFieldTicketStatus : System.Web.UI.UserControl
    {
        private string _keyField;
        private string _valueField;
        private string _defaultValue;
 
        public uxLookupFieldTicketStatus()
        {
            
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            LookupFieldTicketStatus lookup = new LookupFieldTicketStatus();
 
            this.LookupFieldTicketStatusDropDown.Items.AddRange(lookup.getLookupListItemGroup(this.KeyField, this.ValueField));
 
            ListItem selected = this.LookupFieldTicketStatusDropDown.Items.FindByValue(this.DefaultValue);
 
            this.LookupFieldTicketStatusDropDown.SelectedIndex = this.LookupFieldTicketStatusDropDown.Items.IndexOf(selected);
        }
 
        [Category("Data"), Description("The dataset column that will be display field in the dropdown"), Browsable(true)]
        public string KeyField
        {
            get
            {
                return _keyField;
            }
            set
            {
                _keyField = value;
            }
        }
 
        [Category("Data"), Description("The dataset column that will be value field in the dropdown"), Browsable(true)]
        public string ValueField
        {
            get
            {
                return _valueField;
            }
            set
            {
                _valueField = value;
            }
        }
 
        public string DefaultValue
        {
            get
            {
                return _defaultValue;
            }
            set
            {
                _defaultValue = value;
            }
        }
    }
}

Open in new window

0
Comment
Question by:mathieu_cupryk
  • 10
  • 7
17 Comments
 
LVL 14

Expert Comment

by:GiftsonDJohn
ID: 24285070
Hi,

Similarly create another function as below

 [Category("Data"), Description("Selected Index of the DropDownList"), Browsable(true)]
        public string SelectedIndex
        {
            get
            {
                return LookupFieldTicketStatusDropDown.SelectedIndex;
            }          
        }

 [Category("Data"), Description("Selected Text of the DropDownList"), Browsable(true)]
        public string SelectedText
        {
            get
            {
                return LookupFieldTicketStatusDropDown.SelectedText;
            }          
        }

 [Category("Data"), Description("Selected Valueof the DropDownList"), Browsable(true)]
        public string SelectedValue
        {
            get
            {
                return LookupFieldTicketStatusDropDown.SelectedValue;
            }          
        }

0
 

Author Comment

by:mathieu_cupryk
ID: 24285110
Error      3      Cannot implicitly convert type 'int' to 'string'      C:\svn\SIDWEBMYBRANCH\code\KORE.SIDWebClient.UI\Controls\Lookup\uxLookupFieldTicketStatus.ascx.cs      38      24      KORE.SIDWebClient.UI

 [Category("Data"), Description("Selected Index of the DropDownList"), Browsable(true)]
        public string SelectedIndex
        {
            get
            {
                return LookupFieldTicketStatusDropDown.SelectedIndex;
            }
        }
=====================================================================

Error      5      'System.Web.UI.WebControls.DropDownList' does not contain a definition for 'SelectedText' and no extension method 'SelectedText' accepting a first argument of type 'System.Web.UI.WebControls.DropDownList' could be found (are you missing a using directive or an assembly reference?)      C:\svn\SIDWEBMYBRANCH\code\KORE.SIDWebClient.UI\Controls\Lookup\uxLookupFieldTicketStatus.ascx.cs      47      56      KORE.SIDWebClient.UI
[Category("Data"), Description("Selected Text of the DropDownList"), Browsable(true)]
        public string SelectedText
        {
            get
            {
                return LookupFieldTicketStatusDropDown.SelectedText;
            }
        }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KORE.SIDWebClient.BLL;
using System.ComponentModel;
 
namespace KORE.SIDWebClient.UI.Controls
{
    public partial class uxLookupFieldTicketStatus : System.Web.UI.UserControl
    {
        private string _keyField;
        private string _valueField;
        private string _defaultValue;
 
        public uxLookupFieldTicketStatus()
        {
            
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            LookupFieldTicketStatus lookup = new LookupFieldTicketStatus();
 
            this.LookupFieldTicketStatusDropDown.Items.AddRange(lookup.getLookupListItemGroup(this.KeyField, this.ValueField));
 
            ListItem selected = this.LookupFieldTicketStatusDropDown.Items.FindByValue(this.DefaultValue);
 
            this.LookupFieldTicketStatusDropDown.SelectedIndex = this.LookupFieldTicketStatusDropDown.Items.IndexOf(selected);
        }
        [Category("Data"), Description("Selected Index of the DropDownList"), Browsable(true)]
        public string SelectedIndex
        {
            get
            {
                return LookupFieldTicketStatusDropDown.SelectedIndex;
            }
        }
 
        [Category("Data"), Description("Selected Text of the DropDownList"), Browsable(true)]
        public string SelectedText
        {
            get
            {
                return LookupFieldTicketStatusDropDown.SelectedText;
            }
        }
 
        [Category("Data"), Description("Selected Valueof the DropDownList"), Browsable(true)]
        public string SelectedValue
        {
            get
            {
                return LookupFieldTicketStatusDropDown.SelectedValue;
            }
        }
 
        [Category("Data"), Description("The dataset column that will be display field in the dropdown"), Browsable(true)]
        public string KeyField
        {
            get
            {
                return _keyField;
            }
            set
            {
                _keyField = value;
            }
        }
 
        [Category("Data"), Description("The dataset column that will be value field in the dropdown"), Browsable(true)]
        public string ValueField
        {
            get
            {
                return _valueField;
            }
            set
            {
                _valueField = value;
            }
        }
 
        public string DefaultValue
        {
            get
            {
                return _defaultValue;
            }
            set
            {
                _defaultValue = value;
            }
        }
    }
}

Open in new window

0
 
LVL 14

Expert Comment

by:GiftsonDJohn
ID: 24285133
[Category("Data"), Description("Selected Index of the DropDownList"), Browsable(true)]
        public intSelectedIndex
        {
            get
            {
                return LookupFieldTicketStatusDropDown.SelectedIndex;
            }
        }
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:GiftsonDJohn
ID: 24285137
typo mistake :-)
0
 
LVL 14

Expert Comment

by:GiftsonDJohn
ID: 24285138
[Category("Data"), Description("Selected Index of the DropDownList"), Browsable(true)]
        public int SelectedIndex
        {
            get
            {
                return LookupFieldTicketStatusDropDown.SelectedIndex;
            }
        }
0
 

Author Comment

by:mathieu_cupryk
ID: 24286827
SelectedText does not exist.
return LookupFieldTicketStatusDropDown.? is it Text?

[Category("Data"), Description("Selected Text of the DropDownList"), Browsable(true)]
        public string SelectedText
        {
            get
            {
                return LookupFieldTicketStatusDropDown.Text;
            }
        }


0
 

Author Comment

by:mathieu_cupryk
ID: 24286874
[Category("Data"), Description("Selected Text of the DropDownList"), Browsable(true)]
        public string SelectedText
        {
            get
            {
                return LookupFieldTicketStatusDropDown.SelectedItem.Text;
            }
        }
?
http://www.dreamincode.net/code/snippet3028.htm
0
 

Author Comment

by:mathieu_cupryk
ID: 24286927
       protected void btnSaveExit_Click(object sender, EventArgs e)
        {
           
           // Instantiate business object
           BLL.Tickets tickets = new BLL.Tickets();
           tickets.TicketType = uxLookupFieldTicketType1.SelectedValue;


           
        }

The values are null?
0
 

Author Comment

by:mathieu_cupryk
ID: 24287853
John where are u, man I need you.
0
 
LVL 14

Expert Comment

by:GiftsonDJohn
ID: 24288382
Hi,

The selected value of dropdown list won't be null unless it doesn't have any items in it. If the dropdown list has atleat 1 item in it then it will return that value as selected value.

So you have to check

1. Whether the items are getting loaded into the Dropdown List
2. BLL.Tickets tickets = new BLL.Tickets(); has any problem.

Post the stack trace. it will really help to find the issue.
0
 

Author Comment

by:mathieu_cupryk
ID: 24288673
It doesn not bumb. But it is just null;
when I assign the value of the dropdownlist to the field of the object.
attached is my bo object
from the BLL

I have not yet wrote the DAL.

I can do this once all the stored procs are done.

using System;
using System.Text;
using System.Xml;
using System.Collections;
using System.Diagnostics;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Reflection;
using System.Xml.Serialization;
using System.IO;
using System.Collections.Generic;
 
 
 
namespace KORE.SIDWebClient.BLL
{
 
    [Serializable]
    public partial class Tickets
    {
 
 
        private int? ticketID = 0;
        private string ticketNumber = "";
        private string ticketType = "";
        private string ticketStatus = "";
        private string ticketSeverity = "";
        private string shortDescription = "";
        private string externalTicket = "";
        private string reasonMenu = "";
        private string problemNote = "";
        private string solutionNote = "";
        private string actionNote = "";
        private string followupNote = "";
        private bool? companiesFlag = false;
        private string agentCreated = "";
        private DateTime? dateCreated = System.DateTime.Now;
        private DateTime? dateLastModified = System.DateTime.Now;
        private string agentClosed = "";
        private DateTime? dateClosed = System.DateTime.Now;
        private string agentFollowup = "";
        private DateTime? followupBy = System.DateTime.Now;
        private bool? deletedFlag = false;
        private string ticketTypeOld = "";
        private string assignedTo = "";
        private string requestType = "";
        private string serviceImpact = "";
        private DateTime? dateTimeAssigned = System.DateTime.Now;
        private string priority = "";
        private DateTime? dateAssigned = System.DateTime.Now;
        private string trackIt = "";
        private string contactMethod = "";
        private string locationSIMs = "";
        private string userID = "";
        private string ticketApplicationType = "";
        private int? accountID = 0;
 
        
        #region "constructors"
 
        //public Company(int @companyID)
        //{
 
        //    DataSet CompanyDataSet = CompanyData.GetCompanyDataSet(@companyID);
 
        //    this.CompanyName = CompanyDataSet.Tables[0].Rows[0]["Company"].ToString();
        //    this.AccountNumber = CompanyDataSet.Tables[0].Rows[0]["AccountNumber"].ToString();
        //    this.AccountRepresentative = CompanyDataSet.Tables[0].Rows[0]["AccountRepresentative"].ToString();
        //    this.AgentCreated = CompanyDataSet.Tables[0].Rows[0]["AgentCreated"].ToString();
        //    this.Country = CompanyDataSet.Tables[0].Rows[0]["Country"].ToString();
        //    this.DeviceInfo = CompanyDataSet.Tables[0].Rows[0]["DeviceInfo"].ToString();
        //    this.Email = CompanyDataSet.Tables[0].Rows[0]["Email"].ToString();
        //    this.EnterpriseID = int.Parse(CompanyDataSet.Tables[0].Rows[0]["EnterpriseID"].ToString());
        //    this.EnterpriseAccountStatus = CompanyDataSet.Tables[0].Rows[0]["EnterpriseAccountStatus"].ToString();
        //    this.EnterpriseSolutionNote = CompanyDataSet.Tables[0].Rows[0]["EnterpriseSolutionNote"].ToString();
        //    this.EnterpriseType = CompanyDataSet.Tables[0].Rows[0]["EnterpriseType"].ToString();
        //    this.Fax = CompanyDataSet.Tables[0].Rows[0]["Fax"].ToString();
        //    this.IndustryType = CompanyDataSet.Tables[0].Rows[0]["IndustryType"].ToString();
        //    this.Phone = CompanyDataSet.Tables[0].Rows[0]["DeviceInfo"].ToString();
        //    this.ServiceFlagGPRS = bool.Parse(CompanyDataSet.Tables[0].Rows[0]["ServiceFlagGPRS"].ToString());
        //    this.ServiceFlagSMS = bool.Parse(CompanyDataSet.Tables[0].Rows[0]["ServiceFlagSMS"].ToString());
        //    this.ServiceFlagVoice = bool.Parse(CompanyDataSet.Tables[0].Rows[0]["ServiceFlagVoice"].ToString());
        //    this.PriorityLevelOverride = bool.Parse(CompanyDataSet.Tables[0].Rows[0]["PriorityLevelOverride"].ToString());
        //    this.PriorityLevel = CompanyDataSet.Tables[0].Rows[0]["PriorityLevel"].ToString();
        //    this.ContractType = CompanyDataSet.Tables[0].Rows[0]["ContractType"].ToString();
 
        //    string csd = CompanyDataSet.Tables[0].Rows[0]["ContractStartDate"].ToString();
        //    this.ContractStartDate = (csd.Equals("")) ? DateTime.MinValue : DateTime.Parse(csd);
 
        //    string ced = CompanyDataSet.Tables[0].Rows[0]["ContractEndDate"].ToString();
        //    this.ContractEndDate = (ced.Equals("")) ? DateTime.MinValue : DateTime.Parse(ced);
 
        //    string dc = CompanyDataSet.Tables[0].Rows[0]["DateCreated"].ToString();
        //    this.DateCreated = (dc.Equals("")) ? DateTime.MinValue : DateTime.Parse(dc);
 
        //    string dlm = CompanyDataSet.Tables[0].Rows[0]["DateLastModified"].ToString();
        //    this.DateLastModified = (dlm.Equals("")) ? DateTime.MinValue : DateTime.Parse(dlm);
        //}
        #endregion
 
 
        #region Properties
        public System.Int32? TicketID
        {
            get
            {
                return ticketID;
            }
            set
            {
                ticketID = value;
            }
        }
 
        public System.String TicketNumber
        {
            get
            {
                return ticketNumber;
            }
            set
            {
                ticketNumber = value;
            }
        }
 
        public System.String TicketType
        {
            get
            {
                return ticketType;
            }
            set
            {
                ticketType = value;
            }
        }
 
        public System.String TicketStatus
        {
            get
            {
                return ticketStatus;
            }
            set
            {
                ticketStatus = value;
            }
        }
 
        public System.String TicketSeverity
        {
            get
            {
                return ticketSeverity;
            }
            set
            {
                ticketSeverity = value;
            }
        }
 
        public System.String ShortDescription
        {
            get
            {
                return shortDescription;
            }
            set
            {
                shortDescription = value;
            }
        }
 
        public System.String ExternalTicket
        {
            get
            {
                return externalTicket;
            }
            set
            {
                externalTicket = value;
            }
        }
 
        public System.String ReasonMenu
        {
            get
            {
                return reasonMenu;
            }
            set
            {
                reasonMenu = value;
            }
        }
 
        public System.String ProblemNote
        {
            get
            {
                return problemNote;
            }
            set
            {
                problemNote = value;
            }
        }
 
        public System.String SolutionNote
        {
            get
            {
                return solutionNote;
            }
            set
            {
                solutionNote = value;
            }
        }
 
        public System.String ActionNote
        {
            get
            {
                return actionNote;
            }
            set
            {
                actionNote = value;
            }
        }
 
        public System.String FollowupNote
        {
            get
            {
                return followupNote;
            }
            set
            {
                followupNote = value;
            }
        }
 
        public System.Boolean? CompaniesFlag
        {
            get
            {
                return companiesFlag;
            }
            set
            {
                companiesFlag = value;
            }
        }
 
        public System.String AgentCreated
        {
            get
            {
                return agentCreated;
            }
            set
            {
                agentCreated = value;
            }
        }
 
        public System.DateTime? DateCreated
        {
            get
            {
                return dateCreated;
            }
            set
            {
                dateCreated = value;
            }
        }
 
        public System.DateTime? DateLastModified
        {
            get
            {
                return dateLastModified;
            }
            set
            {
                dateLastModified = value;
            }
        }
 
        public System.String AgentClosed
        {
            get
            {
                return agentClosed;
            }
            set
            {
                agentClosed = value;
            }
        }
 
        public System.DateTime? DateClosed
        {
            get
            {
                return dateClosed;
            }
            set
            {
                dateClosed = value;
            }
        }
 
        public System.String AgentFollowup
        {
            get
            {
                return agentFollowup;
            }
            set
            {
                agentFollowup = value;
            }
        }
 
        public System.DateTime? FollowupBy
        {
            get
            {
                return followupBy;
            }
            set
            {
                followupBy = value;
            }
        }
 
        public System.Boolean? DeletedFlag
        {
            get
            {
                return deletedFlag;
            }
            set
            {
                deletedFlag = value;
            }
        }
 
        public System.String TicketTypeOld
        {
            get
            {
                return ticketTypeOld;
            }
            set
            {
                ticketTypeOld = value;
            }
        }
 
        public System.String AssignedTo
        {
            get
            {
                return assignedTo;
            }
            set
            {
                assignedTo = value;
            }
        }
 
        public System.String RequestType
        {
            get
            {
                return requestType;
            }
            set
            {
                requestType = value;
            }
        }
 
        public System.String ServiceImpact
        {
            get
            {
                return serviceImpact;
            }
            set
            {
                serviceImpact = value;
            }
        }
 
        public System.DateTime? DateTimeAssigned
        {
            get
            {
                return dateTimeAssigned;
            }
            set
            {
                dateTimeAssigned = value;
            }
        }
 
        public System.String Priority
        {
            get
            {
                return priority;
            }
            set
            {
                priority = value;
            }
        }
 
        public System.DateTime? DateAssigned
        {
            get
            {
                return dateAssigned;
            }
            set
            {
                dateAssigned = value;
            }
        }
 
        public System.String TrackIt
        {
            get
            {
                return trackIt;
            }
            set
            {
                trackIt = value;
            }
        }
 
        public System.String ContactMethod
        {
            get
            {
                return contactMethod;
            }
            set
            {
                contactMethod = value;
            }
        }
 
        public System.String LocationSIMs
        {
            get
            {
                return locationSIMs;
            }
            set
            {
                locationSIMs = value;
            }
        }
 
        public System.String UserID
        {
            get
            {
                return userID;
            }
            set
            {
                userID = value;
            }
        }
 
        public System.String TicketApplicationType
        {
            get
            {
                return ticketApplicationType;
            }
            set
            {
                ticketApplicationType = value;
            }
        }
 
        public System.Int32? AccountID
        {
            get
            {
                return accountID;
            }
            set
            {
                accountID = value;
            }
        }
 
        #endregion
 
    }
}

Open in new window

0
 
LVL 14

Accepted Solution

by:
GiftsonDJohn earned 2000 total points
ID: 24288820
It is so difficult to recognize the problem without the Stack Trace. It will clearly says the problem. Please post the stack trace from your page.
0
 

Author Comment

by:mathieu_cupryk
ID: 24288826
how can I do this?
0
 
LVL 14

Expert Comment

by:GiftsonDJohn
ID: 24288849
Is it throwing any null reference errror?
0
 

Author Comment

by:mathieu_cupryk
ID: 24290919
It just is empty when I click on the submit button.
0
 

Author Closing Comment

by:mathieu_cupryk
ID: 31577137
Excellent job. I created a sep question.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question