Hi,
I have a GridTemplateColumn on a RadGrid. This Template contains a Label control for ItemTemplate and a DropDownList for the EditItemTemplate. The label is bound to a field from the DataTable. Now, When the Grid row goes into Edit mode, I need to set the selectedindex of the dropdown to show the original value from the label. How and where would I do that? I don't seem to have access to the Label control from within the ItemDataBound event for the GridEditableItem. Somebody please help.
Babu.
Here is my Markup:
And here is my code:
I have a GridTemplateColumn on a RadGrid. This Template contains a Label control for ItemTemplate and a DropDownList for the EditItemTemplate. The label is bound to a field from the DataTable. Now, When the Grid row goes into Edit mode, I need to set the selectedindex of the dropdown to show the original value from the label. How and where would I do that? I don't seem to have access to the Label control from within the ItemDataBound event for the GridEditableItem. Somebody please help.
Babu.
Here is my Markup:
<telerik:GridTemplateColumn DataField="role" HeaderText="Role" UniqueName="Role"> |
<EditItemTemplate> |
<asp:DropDownList ID="ddlRoles" runat="server" DataTextField="Role" DataValueField="Role" |
Width="125px"> |
</asp:DropDownList> |
</EditItemTemplate> |
<ItemTemplate> |
<asp:Label ID="lblRole" runat="server" Text='<%# Bind("role") %>'></asp:Label> |
</ItemTemplate> |
<ItemStyle Wrap="False" /> |
</telerik:GridTemplateColumn> |
And here is my code:
protected void rgUserAdmin_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item.ItemType == GridItemType.EditItem) |
{ |
GridEditableItem edtItem = (GridEditableItem)e.Item; |
DropDownList ddl = (DropDownList)edtItem.FindControl("ddlRoles"); |
if (null != ddl) |
{ |
ddl.DataSource = ForecastUtils.GetAllMetricUserRoles(); |
ddl.DataTextField = "role"; |
ddl.DataValueField = "role"; |
// this is where I need to set the value of this ddl to the value |
// from the Label on the ItemTemplate. |
ddl.SelectedIndex = -1; |
ddl.DataBind(); |
} |
} |
} |