Link to home
Create AccountLog in
Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada

asked on

Web User Control Drop Down List does not show selected item

The form and behind the form code.

<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>            

 protected void btnSaveExit_Click(object sender, EventArgs e)
        {
           
           // Instantiate business object
          BLL.Ticket ticket = new BLL.Ticket();
          // ticket.TicketType =
          Response.Write (uxLookupFieldTicketType1.SelectedValue);


           
        }

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="uxLookupFieldTicketType.ascx.cs" Inherits="KORE.SIDWebClient.UI.Controls.uxLookupFieldTicketType" %>
 
 
<asp:DropDownList ID="LookupTypeTicketDropDown" AppendDataBoundItems="true" Width="200px" runat="server">
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownList><br />
<asp:RequiredFieldValidator id="CVLookupTypeTicketDropDown"
        Text="(Required)" 
        InitialValue=""
        ControlToValidate="LookupTypeTicketDropDown"
        Runat="server" />
 
 
private string _keyField;
        private string _valueField;
        private string _defaultValue;
 
        public uxLookupFieldTicketType()
        {
            
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            LookupTypeTicket lookup = new LookupTypeTicket();
 
            this.LookupTypeTicketDropDown.Items.AddRange(lookup.getLookupListItemGroup(this.KeyField, this.ValueField));
 
            ListItem selected = this.LookupTypeTicketDropDown.Items.FindByValue(this.DefaultValue);
 
            this.LookupTypeTicketDropDown.SelectedIndex = this.LookupTypeTicketDropDown.Items.IndexOf(selected);
        }
 
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        ///
        [Category("Data"), Description("Selected Index of the DropDownList"), Browsable(true)]
        public int SelectedIndex
        {
            get
            {
                return LookupTypeTicketDropDown.SelectedIndex;
            }
        }
 
        [Category("Data"), Description("Selected Text of the DropDownList"), Browsable(true)]
        public string SelectedText
        {
            get
            {
                return LookupTypeTicketDropDown.SelectedItem.Text;
            }
        }
 
        [Category("Data"), Description("Selected Valueof the DropDownList"), Browsable(true)]
        public string SelectedValue
        {
            get
            {
                return LookupTypeTicketDropDown.SelectedValue;
            }
        }
 
        /// <summary>
        /// ////////////////////////////////////////////////////////////////////////////////////////
        /// </summary>   
        [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

dropdown.gif
Avatar of mathieu_cupryk
mathieu_cupryk
Flag of Canada image

ASKER

I even tried this

    string val = (uxLookupFieldTicketType1.FindControl("LookupTypeTicketDropDown") as DropDownList).SelectedValue;
          Response.Write(val);
         still giving me null
ASKER CERTIFIED SOLUTION
Avatar of eyal_mt
eyal_mt
Flag of Israel image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
He is a snap shot. What am I doing wrong.

onload.gif
Can you show the return value of:
lookup.getLookupListItemGroup(this.KeyField, this.ValueField)
what type are the objects and what is their value.
I forgot to put the IF (!postback)
nice try.