I am using radgrid and having GridboundColumn and GridDropDownColumns in it with edit/insert feature. I am implementing the feature like if user click on Edit of the gird the form is opening up enabling the user to make the changes, but depending on value of 'qualificaton' dropdown i have to disbale/enable the dropdown 'Profession' so i used itemdatabound event of the radgrid and able to disable the dropdown(Profession) depending on 'qualificaton' dropdown ... now i also have autopostback true on dropdown (Profession) to enable/disable 'profession' dropdown
i.e. say dropdown 1st has value as 1 and user click on Edit and i disabled the 2nd dropdown using itemdatabound event. Now user changed the 1st dropdown value to 2 now i have to enable the dropdown two so tried to use indexchangedevent for 1st dropdown(autopostback = true) but i am not able to enable the dropdown two may be because i disabled it earlier onitemdatabound event. Please let me know the workaround to achieve it.
<telerik:RadGrid ID="radGrid1" runat="server" AllowAutomaticDeletes="True"
AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True"
AllowSorting="True" DataSourceID="SqlDataSource1" GridLines="None"
onitemcreated="radGrid1_ItemCreated"
onitemupdated="radGrid1_ItemUpdated" PageSize="3" Skin="Office2007"
Width="600px" onitemdatabound="radGrid1_ItemDataBound"
onselectedindexchanged="radGrid1_SelectedIndexChanged">
<clientsettings>
<scrolling allowscroll="True" usestaticheaders="True" />
</clientsettings>
<mastertableview autogeneratecolumns="False" commanditemdisplay="Top"
datakeynames="user_id" datasourceid="SqlDataSource1" pagesize="5">
<Columns>
<telerik:GridBoundColumn DataField="user_id" HeaderText="ID" ReadOnly="True"
SortExpression="user_id" UniqueName="userid" Visible="False">
</telerik:GridBoundColumn>
<telerik:GridDropDownColumn DataField="qualificaton"
DataSourceID="SqlDataSource2" DropDownControlType="DropDownList"
HeaderText="Qualificaton" ListTextField="qualificaton"
ListValueField="qualificaton" UniqueName="qualificaton">
</telerik:GridDropDownColumn>
<telerik:GridDropDownColumn DataField="field"
DataSourceID="SqlDataSource3" DropDownControlType="DropDownList"
HeaderText="Profession" ListTextField="field"
ListValueField="field" UniqueName="field">
</telerik:GridDropDownColumn>
</columns>
</mastertableview>
</telerik:radgrid>
protected void radGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
GridEditManager editMan = editedItem.EditManager;
GridDropDownColumnEditor ddl1 = editMan.GetColumnEditor("qualificaton") as GridDropDownColumnEditor;
if (ddlStaff.SelectedText == "1")
{
if (e.Item.ItemType == GridItemType.EditFormItem)
{
GridEditableItem editedItem1 = e.Item as GridEditableItem;
editedItem1["field"].Enabled = false;
}
}
}
}
protected void radGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
// to assign the indexchangedevent and to set autopostback true of the dropdown in edit mode of the radgrid
GridEditableItem item = (GridEditableItem)e.Item;
DropDownList ddl1 = item["qualificaton"].Controls[0] as DropDownList;
ddl1.AutoPostBack = true;
ddl1.SelectedIndexChanged += new EventHandler(this.ddl1_SelectedIndexChanged);
}
}
void ddlStaff_SelectedIndexChanged(object sender, EventArgs e)
{
GridEditableItem editedItem = (sender as DropDownList).NamingContainer as GridEditableItem;
DropDownList ddl1 = editedItem["qualificaton"].Controls[0] as DropDownList;
DropDownList ddl2 = editedItem["field"].Controls[0] as DropDownList;
if (ddl1.SelectedValue == "1")
{
ddl2.Enabled = false;
}
else
{
ddl2.Enabled = true;
}
}
i.e. say dropdown 1st has value as 1 and user click on Edit and i disabled the 2nd dropdown using itemdatabound event. Now user changed the 1st dropdown value to 2 now i have to enable the dropdown two so tried to use indexchangedevent for 1st dropdown(autopostback = true) but i am not able to enable the dropdown two may be because i disabled it earlier onitemdatabound event. Please let me know the workaround to achieve it.
<telerik:RadGrid ID="radGrid1" runat="server" AllowAutomaticDeletes="True"
AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True"
AllowSorting="True" DataSourceID="SqlDataSource1" GridLines="None"
onitemcreated="radGrid1_ItemCreated"
onitemupdated="radGrid1_ItemUpdated" PageSize="3" Skin="Office2007"
Width="600px" onitemdatabound="radGrid1_ItemDataBound"
onselectedindexchanged="radGrid1_SelectedIndexChanged">
<clientsettings>
<scrolling allowscroll="True" usestaticheaders="True" />
</clientsettings>
<mastertableview autogeneratecolumns="False" commanditemdisplay="Top"
datakeynames="user_id" datasourceid="SqlDataSource1" pagesize="5">
<Columns>
<telerik:GridBoundColumn DataField="user_id" HeaderText="ID" ReadOnly="True"
SortExpression="user_id" UniqueName="userid" Visible="False">
</telerik:GridBoundColumn>
<telerik:GridDropDownColumn DataField="qualificaton"
DataSourceID="SqlDataSource2" DropDownControlType="DropDownList"
HeaderText="Qualificaton" ListTextField="qualificaton"
ListValueField="qualificaton" UniqueName="qualificaton">
</telerik:GridDropDownColumn>
<telerik:GridDropDownColumn DataField="field"
DataSourceID="SqlDataSource3" DropDownControlType="DropDownList"
HeaderText="Profession" ListTextField="field"
ListValueField="field" UniqueName="field">
</telerik:GridDropDownColumn>
</columns>
</mastertableview>
</telerik:radgrid>
protected void radGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
GridEditManager editMan = editedItem.EditManager;
GridDropDownColumnEditor ddl1 = editMan.GetColumnEditor("qualificaton") as GridDropDownColumnEditor;
if (ddlStaff.SelectedText == "1")
{
if (e.Item.ItemType == GridItemType.EditFormItem)
{
GridEditableItem editedItem1 = e.Item as GridEditableItem;
editedItem1["field"].Enabled = false;
}
}
}
}
protected void radGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
// to assign the indexchangedevent and to set autopostback true of the dropdown in edit mode of the radgrid
GridEditableItem item = (GridEditableItem)e.Item;
DropDownList ddl1 = item["qualificaton"].Controls[0] as DropDownList;
ddl1.AutoPostBack = true;
ddl1.SelectedIndexChanged += new EventHandler(this.ddl1_SelectedIndexChanged);
}
}
void ddlStaff_SelectedIndexChanged(object sender, EventArgs e)
{
GridEditableItem editedItem = (sender as DropDownList).NamingContainer as GridEditableItem;
DropDownList ddl1 = editedItem["qualificaton"].Controls[0] as DropDownList;
DropDownList ddl2 = editedItem["field"].Controls[0] as DropDownList;
if (ddl1.SelectedValue == "1")
{
ddl2.Enabled = false;
}
else
{
ddl2.Enabled = true;
}
}