Retrieving the Value On SelectedIndexChange

4 posts, 1 answers
  1. Stephen Kumor
    Stephen Kumor avatar
    8 posts
    Member since:
    Mar 2010

    Posted 05 Mar 2010 Link to this post

    I am having an issue trying to get the RadComboBox's Selected Value on the SelectedIndexChanged event.  The odd thing is that during the SelectedIndexChanged event when I check e it has the old value (e.OldValue) and the old text (e.OldText) but the e text (e.Text) shows up correctly but the e.Value turns to null or "".  Why is my selected value turning to an empty string/null on SelectedIndexChange?


    See my code below.  Thanks for any help.
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SCRDropDown.ascx.cs" Inherits="AMC.OnlineSCR.Web.UserControls.SCRDropDown" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    <link href="../stylesheets/tkComboBox.css" rel="stylesheet" type="text/css" /> 
    <!-- content start --> 
    <asp:Label runat="server"  
        ID="lblSelectASCR"  
        AssociatedControlID="cbSelectASCR" 
        Text="Select A SCR:" /> 
     
    <telerik:RadComboBox  
        runat="server" 
        AutoPostBack="true"  
        ID="cbSelectASCR"  
        DataTextField="SCR_NUMBER" 
        EnableLoadOnDemand="True" 
        Width="670px"  
        Height="190px" 
        HighlightTemplatedItems="true"  
        OnDataBound="cbSelectASCR_DataBound"  
        OnItemDataBound="cbSelectASCR_ItemDataBound" 
        OnSelectedIndexChanged="cbSelectASCR_SelectedIndexChanged" 
        OnItemsRequested="cbSelectASCR_ItemsRequested"
        <HeaderTemplate> 
            <ul> 
                <li class="col1">SCR Number</li> 
                <li class="titleCol">Title</li> 
                <li class="col3">Status</li> 
                <li class="col1">Date Submitted</li> 
            </ul> 
        </HeaderTemplate> 
        <ItemTemplate> 
            <ul> 
                <li class="col1"
                    <%# DataBinder.Eval(Container.DataItem, "SCR_NUMBER") %></li
                <li class="titleCol"
                    <%# DataBinder.Eval(Container.DataItem, "TITLE") %></li
                <li class="col3"
                    <%# DataBinder.Eval(Container.DataItem, "STATUS_NAME") %></li
                <li class="col1"
                     <%# DataBinder.Eval(Container.DataItem, "DATE_OF_SUBMITTAL", "{0:dd MMM yyyy}") %></li
            </ul> 
        </ItemTemplate> 
        <FooterTemplate> 
            A total of 
            <asp:Literal runat="server" ID="cbSelectASCRCount" /> 
            items 
        </FooterTemplate> 
    </telerik:RadComboBox> 
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using Telerik.Web.UI; 
    using System.Data; 
    using System.IO; 
    using AMC.OnlineSCR.BusinessLayer.BusinessObjects; 
    using AMC.OnlineSCR.BusinessLayer.Facade; 
    using AMC.OnlineSCR.Web.Components; 
     
    namespace AMC.OnlineSCR.Web.UserControls 
        public partial class SCRDropDown : System.Web.UI.UserControl 
        { 
            private ISCRMainDataFacade SCRMainFacade = new SCRMainDataFacade(); 
            int m_SCRID; 
     
            public int SCRID 
            { 
                get { return m_SCRID; } 
                set { m_SCRID = value; } 
            } 
     
            protected void Page_Load(object sender, EventArgs e) 
            { 
                DataSet ds = SCRMainFacade.GetMiniSCRAll(); 
                cbSelectASCR.DataSource = ds; 
                cbSelectASCR.DataBind(); 
            } 
     
            protected void cbSelectASCR_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
            { 
                SCRID = Convert.ToInt16(e.Value.ToString()); 
                //SCRID = ((DataRowView)e.Item.DataItem)["SCR_NUMBER"].ToString(); 
            } 
     
            protected void cbSelectASCR_DataBound(object sender, EventArgs e) 
            { 
                //set the initial footer label 
                ((Literal)cbSelectASCR.Footer.FindControl("cbSelectASCRCount")).Text = Convert.ToString(cbSelectASCR.Items.Count); 
            } 
     
            protected void cbSelectASCR_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e) 
            { 
                //get all customers whose name starts with e.Text 
                DataSet ds = SCRMainFacade.GetMiniSCRAllLike(e.Text); 
                cbSelectASCR.DataSource = ds; 
                cbSelectASCR.DataBind(); 
            } 
     
            protected void cbSelectASCR_ItemDataBound(object sender, RadComboBoxItemEventArgs e) 
            { 
                //set the Text and Value property of every item 
                //here you can set any other properties like Enabled, ToolTip, Visible, etc. 
                e.Item.Text = (((DataRowView)e.Item.DataItem)["SCR_NUMBER"].ToString()) + " - " + (((DataRowView)e.Item.DataItem)["TITLE"].ToString()); 
                e.Item.Value = ((DataRowView)e.Item.DataItem)["SCR_ID"].ToString(); 
            } 
        } 

  2. Answer
    robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 05 Mar 2010 Link to this post

    Why not try this:

    cbSelectASCR.SelectedValue

    Instead of using e.Value and see if that works.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Stephen Kumor
    Stephen Kumor avatar
    8 posts
    Member since:
    Mar 2010

    Posted 05 Mar 2010 Link to this post

    That's the curve ball.  Inside the cbSelectASCR_SelectedIndexChanged event the SelectedItem=null  and SelectedValue="".  I am baffled because the cbSelectASCR.Text holds my value of "009-669A - Second Test SCR".  Why would it persist the Text but not have a SelectedValue or SelectedItem?  Can it be the logic of adding Text and Value properties on the ItemDataBound Event...which it shouldn't because that is texbook from a Telerik example. 

    Confucius say....Man who stands on toilet is high on pot!


  5. Stephen Kumor
    Stephen Kumor avatar
    8 posts
    Member since:
    Mar 2010

    Posted 05 Mar 2010 Link to this post

    Figured it out.  I was binding my initial data on Page_Load and I did not have it in a (!Page.IsPostBack).  Once I put the databinding in the (!Page.IsPostBack) it worked like a charm.  It must have been with the ItemsRequested as I set a new datasource in there. Robert...I will mark you as answered just because you are the only one who actually replied.  Thanks.
Back to Top