(828) 862-6667

Telerik Blogs



Telerik RADGrid: Fill a RADCombobox when editing a row with a user control

by Rich Winslow | Mar 21, 2011

It is easy to fill a textbox using an EVAL statement when you edit a row in a RADGrid.

RADGrid html segment

</Columns>

<EditFormSettings UserControlName="ctlUserEdit.ascx" EditFormType="WebUserControl">
<EditColumn UniqueName="EditCommandColumn">
</EditColumn>
</EditFormSettings>
</MasterTableView>

RADGrid User Control Code Behind

<tr>
<td>
City
</td>
<td>
<asp:TextBox ID="txtCity" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.City") %>'></asp:TextBox>
</td>
</tr>v <tr>
<td>
State
</td>v <td>
<telerik:RadCombobox ID="lstStateList" runat="server" MarkFirstMatch="true" AllowCustomText="false" DataTextField="Abbreviation" DataValueField="Abbreviation"
Text='<%# DataBinder.Eval( Container, "DataItem.State") %>'>
<ExpandAnimation Type="InBounce" Duration="300" />
<CollapseAnimation Type="OutQuint" Duration="200" />
</telerik:RadCombobox>
</td>

User Control Code Behind

The trick is to remember to set the DATASOURCE to nothing so that the DataBinding doesn't override what you set in code behind. If you don't explicitly set the DataSource property then you'll have the first item selected regardless of what the database value is.

txtCity.Text = .Item("City") & ""

lstStateList.SelectedIndex = -1
Dim objItem As Telerik.Web.UI.RadComboBoxItem

objItem = lstStateList.FindItemByValue(.Item("State"))
lstStateList.ClearSelection()
If Not IsNothing(objItem) Then
objItem.Selected = True
End If
lstStateList.DataSource = Nothing

Comment

  1.    
     
     
      
       

Telerik RADGrid: Fill a RADCombobox when editing a row with a user control

by Rich Winslow | Mar 21, 2011

It is easy to fill a textbox using an EVAL statement when you edit a row in a RADGrid.

RADGrid html segment

</Columns>

<EditFormSettings UserControlName="ctlUserEdit.ascx" EditFormType="WebUserControl">
<EditColumn UniqueName="EditCommandColumn">
</EditColumn>
</EditFormSettings>
</MasterTableView>

RADGrid User Control Code Behind

<tr>
<td>
City
</td>
<td>
<asp:TextBox ID="txtCity" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.City") %>'></asp:TextBox>
</td>
</tr>v <tr>
<td>
State
</td>v <td>
<telerik:RadCombobox ID="lstStateList" runat="server" MarkFirstMatch="true" AllowCustomText="false" DataTextField="Abbreviation" DataValueField="Abbreviation"
Text='<%# DataBinder.Eval( Container, "DataItem.State") %>'>
<ExpandAnimation Type="InBounce" Duration="300" />
<CollapseAnimation Type="OutQuint" Duration="200" />
</telerik:RadCombobox>
</td>

User Control Code Behind

The trick is to remember to set the DATASOURCE to nothing so that the DataBinding doesn't override what you set in code behind. If you don't explicitly set the DataSource property then you'll have the first item selected regardless of what the database value is.

txtCity.Text = .Item("City") & ""

lstStateList.SelectedIndex = -1
Dim objItem As Telerik.Web.UI.RadComboBoxItem

objItem = lstStateList.FindItemByValue(.Item("State"))
lstStateList.ClearSelection()
If Not IsNothing(objItem) Then
objItem.Selected = True
End If
lstStateList.DataSource = Nothing

Comment

  1.    
     
     
      
       















Company Info  |   Contact Us  |   Site Map  |   Terms  |   Privacy Policy  |  

Automated Results Computer Consulting LLC, 222 South Caldwell Street, Brevard, NC 28712 (828) 862-6667