Solved

Web User Control Drop Down List does not show selected item

Posted on 2009-05-03
6
374 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

10 Experts available now in Live!

Get 1:1 Help Now