Why Is ComboBox Selected Value Null

2 posts, 0 answers
  1. Perry
    Perry avatar
    62 posts
    Member since:
    Jul 2015

    Posted 26 Oct 2017 Link to this post

     

    I have a RADComboBox on my ASPX page as shown below:

    <telerik:RadComboBox RenderMode="Lightweight" ID="cboxEmployee" runat="server" Width="400" Height="400px" AutoPostBack="false"
                      EmptyMessage="select employee here" CssClass="validationClass" OnSelectedIndexChanged="cboxAccused_SelectedIndexChanged">
                    </telerik:RadComboBox>

    I Bind the ComboBox with this C# code:

    private void BindAccusedDropdowns()
            {
     
     
                using (PSDEntities context = new PSDEntities())
                {
                    cboxEmployee.DataSource = context.LawsonEmployees.OrderBy(s => s.LAST_NAME).ToList();
                    cboxEmployee.DataTextField = "DISPLAY";
                    cboxEmployee.DataValueField = "EID";
                    cboxEmployee.DataBind();
                    cboxEmployee.AllowCustomText = true;
                    cboxEmployee.MarkFirstMatch = true;
                }
            }

     The Box functions properly on the page I can select an employee.

    When I attempt to get the SelectedValue of the comboBox with this code it returns a null value.

    a.EID = Convert.ToInt32(cboxEmployee.SelectedValue);

     

    Any idea why this happening?

  2. Perry
    Perry avatar
    62 posts
    Member since:
    Jul 2015

    Posted 26 Oct 2017 in reply to Perry Link to this post

    I figured out why this was happening.  The issue was where I was binding the dropdown.  I was binding the dropdown on pageload
Back to Top