Solved

Web User Control Drop Down List does not show selected item

Posted on 2009-05-03
6
373 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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