I am doing a task related to telerik grid. In that I have added checkboxes as item templates. When I check the box and if I click on submit, that should be updated in database.
Here is the code I have tried.
aspx:
<telerik:GridTemplateColumn HeaderText="Is Active" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:CheckBox ID="chkIsActive" runat="server" AutoPostBack="true" OnCheckedChanged="chkIsActive_OnCheckedChanged" />
</ItemTemplate>
</telerik:GridTemplateColumn>
aspx.cs code:
public void chkIsActive_OnCheckedChanged(object sender,EventArgs e)
{
CheckBox chkIsActive = (CheckBox)sender;
GridViewRow Row = (GridViewRow)chkIsActive.NamingContainer;
string cid = Row.Cells[1].Text;
bool status = chkIsActive.Checked;
}
Error which I am getting:
Unable to cast object of type ‘Telerik.Web.UI.GridDataItem’ to type ‘System.Web.UI.WebControls.GridViewRow’.
Please resolve my problem.
The problem is that you are trying to cast a telerik Telerik.Web.UI.GridDataItem to a normal gridviewrow, cast it to Telerik.Web.UI.GridDataItem instead.