?
Solved

Web User Control Drop Down List does not show selected item

Posted on 2009-05-03
6
Medium Priority
?
387 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:mathieu_cupryk
  • 4
  • 2
6 Comments
 

Author Comment

by:mathieu_cupryk
ID: 24292481
I even tried this

    string val = (uxLookupFieldTicketType1.FindControl("LookupTypeTicketDropDown") as DropDownList).SelectedValue;
          Response.Write(val);
         still giving me null
0
 
LVL 10

Accepted Solution

by:
eyal_mt earned 1500 total points
ID: 24297712
I fail to see where it is that you are assigning the the keyfield abd valuefield to the DropDown control itself. Perhaps it is the problem.
Also, have you checked that:
lookup.getLookupListItemGroup(this.KeyField, this.ValueField)
really does return the values you expect?
0
 

Author Comment

by:mathieu_cupryk
ID: 24299321
He is a snap shot. What am I doing wrong.

onload.gif
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Expert Comment

by:eyal_mt
ID: 24299489
Can you show the return value of:
lookup.getLookupListItemGroup(this.KeyField, this.ValueField)
what type are the objects and what is their value.
0
 

Author Comment

by:mathieu_cupryk
ID: 24299612
I forgot to put the IF (!postback)
0
 

Author Closing Comment

by:mathieu_cupryk
ID: 31577434
nice try.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Loops Section Overview
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 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