This is a migrated thread and some comments may be shown as answers.

Why Is ComboBox Selected Value Null

1 Answer 86 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Perry
Top achievements
Rank 1
Perry asked on 26 Oct 2017, 02:46 PM

 

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?

1 Answer, 1 is accepted

Sort by
0
Perry
Top achievements
Rank 1
answered on 26 Oct 2017, 07:15 PM
I figured out why this was happening.  The issue was where I was binding the dropdown.  I was binding the dropdown on pageload
Tags
ComboBox
Asked by
Perry
Top achievements
Rank 1
Answers by
Perry
Top achievements
Rank 1
Share this question
or