Search code examples
c#asp.netasp.net-mvcwebformstelerik

How to set the initial value of radDropDownList in requiredfieldvalidator


I have a dropdownlist I want to set the requiredfieldvalidator for the dropdownlist (stateComboBox) Now my question is how can i set initial value for stateComboBox in my RequiredFieldValidator. Thanks in advance

<td>
  <telerik:RadDropDownList ID="stateComboBox" runat="server" DataTextField="SateCode" 
   DataValueField="SateCode" Width="173px">
  </telerik:RadDropDownList>
</td>



 <td>
  <asp:RequiredFieldValidator ID="rvfState" runat="server" ControlToValidate="stateComboBox"
  ErrorMessage="State is Required" ForeColor="#CC0000">*</asp:RequiredFieldValidator>
</td>


Solution

  • On the code behind you can use

    rvfState.InitialValue = 
    

    I guess you will need to grab the first object from your data object. so if it is a DataTable you could say rvfState.InitialValue = dt.rows[0]["SateCode"]