or
<%-- category--%>
<
telerik:GridTemplateColumn
DataField
=
"category"
HeaderText
=
"Category"
SortExpression
=
"category"
UniqueName
=
"category"
>
<
EditItemTemplate
>
<
telerik:RadDropDownList
runat
=
"server"
ID
=
"RadDropDownList3"
DataTextField
=
"category"
AutoPostBack
=
"true"
DataValueField
=
"category"
DefaultMessage
=
"Select Category"
SelectedValue='<%#Bind("category") %>'
OnSelectedIndexChanged="category_SelectedIndexChanged">
<
Items
>
<
telerik:DropDownListItem
Text
=
"India"
Value
=
'India'
/>
<
telerik:DropDownListItem
Text
=
"International"
Value
=
'International'
/>
</
Items
>
</
telerik:RadDropDownList
>
<%-- <
telerik:RadDropDownList
ID
=
"RadDropDownList6"
runat
=
"server"
>
</
telerik:RadDropDownList
>--%>
</
EditItemTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lblcategory"
runat
=
"server"
Text='<%# Bind("category")%>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<%-- sub category--%>
<
telerik:GridTemplateColumn
DataField
=
"sub_category"
HeaderText
=
"Sub Category"
SortExpression
=
"sub_category"
UniqueName
=
"sub_category"
>
<
EditItemTemplate
>
<
telerik:RadDropDownList
runat
=
"server"
ID
=
"RadDropDownList5"
DataTextField
=
"sub_category"
SelectedValue='<%#Bind("sub_category") %>'
AutoPostBack="true" DataValueField="sub_category" DefaultMessage="Select Sub Category" RenderMode="Classic">
</
telerik:RadDropDownList
>
<
asp:HiddenField
ID
=
"hddlsubcategory"
runat
=
"server"
Value='<%# Bind("sub_category") %>' />
</
EditItemTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"Label5"
runat
=
"server"
Text='<%# Bind("sub_category")%>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
and the code behind for this is:
protected void category_SelectedIndexChanged(object sender, DropDownListEventArgs e)
{
RadDropDownList RadDropDownList3 = sender as RadDropDownList;
GridEditFormItem item = RadDropDownList3.NamingContainer as GridEditFormItem;
//Use GridDataItem when dropdown is in item template
//GridDataItem item = RadDropDownList3.NamingContainer as GridDataItem;
RadDropDownList ddlsubcategory = item.FindControl("RadDropDownList5") as RadDropDownList;
if (RadDropDownList3.SelectedValue == "India")
{
//FillCat1();
ddlsubcategory.ClearSelection();
ddlsubcategory.Items.Add(new DropDownListItem("North", "North"));
ddlsubcategory.Items.Add(new DropDownListItem("East", "East"));
ddlsubcategory.Items.Add(new DropDownListItem("West", "West"));
ddlsubcategory.Items.Add(new DropDownListItem("South", "South"));
}
else if (RadDropDownList3.SelectedValue == "International")
{
ddlsubcategory.ClearSelection();
ddlsubcategory.Items.Add(new DropDownListItem("Asia", "Asia"));
ddlsubcategory.Items.Add(new DropDownListItem("Africa", "Africa"));
ddlsubcategory.Items.Add(new DropDownListItem("Australia", "Australia"));
ddlsubcategory.Items.Add(new DropDownListItem("America", "America"));
}
}
protected void gvDetails_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
{
GridEditFormItem item = (GridEditFormItem)e.Item;
//string value = item.GetDataKeyValue("ID").ToString();
RadDropDownList sub_category = item.FindControl("RadDropDownList5") as RadDropDownList;
HiddenField hsubcategory = item.FindControl("hddlsubcategory") as HiddenField;
if (sub_category != null && hsubcategory != null)
{
sub_category.SelectedValue = hsubcategory.Value;
}
}
}