Solved

Web User Control Drop Down List does not show selected item

Posted on 2009-05-03
6
377 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 500 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now