We just discovered an issue with some RadComboBox behavior that doesn't seem quite right. We recently set the MarkFirstMatch="true" property and were running into new errors due to the combo box's SelectedValue="". It seems as though when this property is set to true that the combo box does not default to the first item during page load like it normally does. However, after the page is loaded the SelectedValue is correctly set to the first item in the drop down.
protected void btnTest_Click(object sender, EventArgs e) |
{ |
MessageBox.Show(m_ddltest.SelectedValue.ToString()); |
} |
To recreate this scenario we setup a little test project. Please note that the combo box is never clicked during this test. We simply load it and expect (by default) that the first item in the combo box should be selected by default.
Mark-up
<telerik:RadComboBox ID="m_ddltest" runat="server" MarkFirstMatch="true"></telerik:RadComboBox> |
<tst:TstButton ID="m_btnTest" runat="server" OnClick="btnTest_Click" /> |
Code in Page_Load where we load up the combo box. If you step through this code you will see that the SelectedValue = ""
protected void Page_Load(object sender, EventArgs e) |
{ |
m_ddltest.DataSource = InsuredUnitsFromSession; |
m_ddltest.DataValueField = "InsuredUnitId"; |
m_ddltest.DataTextField = "Name"; |
m_ddltest.DataBind(); |
string test = m_ddltest.SelectedValue.ToString(); |
} |
However, when you click the test button the SelectedValue property is now correctly set. Why is the SelectedValue = "" during the loading of the combo box in Page_Load?
protected void btnTest_Click(object sender, EventArgs e) |
{ |
MessageBox.Show(m_ddltest.SelectedValue.ToString()); |
} |
Thanks in advance for your assistance.
Jonathan