oncheckchanged event inside rad grid

4 posts, 1 answers
  1. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 08 Dec 2011 Link to this post

    I have a grid template column as such

    <telerik:GridTemplateColumn HeaderText="Don't Export" HeaderStyle-Width="40px" DataField="exportCheck"
                    SortExpression="exportCheck" UniqueName="exportCheck">
                        <ItemStyle Width="40px" />
                            <asp:CheckBox ID="printCheck" runat="server" AutoPostBack="false" OnCheckedChanged="printCheckChanged" />

    I am then editing the checkboxes in the code behind to dynamically set them to checked or not

    Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
            If TypeOf e.Item Is GridDataItem Then
                'get the row item
                Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
                'check to see if we need to check the box
                Dim export = DirectCast(item("export").Text, String)
                'get the checkbox
                Dim check As CheckBox = DirectCast(item("exportCheck").Controls(1), CheckBox)
                'if we need to check the box then we will get it and check it
                If (export = "no") Then
                    check.Checked = True
                End If 'if export
            End If 'if e.item
        End Sub 'itemDataBound

    What I need to do is add the oncheckchanged event. Essentially, when a user either checks a box, or unchecks a box, I need to update a database and then show a tool tip telling them it was successful. I tried doing this programmatically, and adding it in the aspx but I can't get anything to work. Can you help me out?
  2. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 08 Dec 2011 Link to this post


    please check below code snippet.
    <telerik:GridTemplateColumn UniqueName="MyColumn">
                                <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged"
                                    AutoPostBack="true" />
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
                CheckBox CheckBox1 = sender as CheckBox;
                // you can access grid row here
                GridDataItem item = CheckBox1.NamingContainer as GridDataItem;
                // perform here DB operation
                TableCell cell = item["MyColumn"];
                cell.ToolTip = DateTime.Now + "_Updated";

    Jayesh Goyani
  3. Natalya
    Natalya avatar
    1 posts
    Member since:
    Sep 2018

    Posted 05 Sep 2018 in reply to Jayesh Goyani Link to this post

    Hello Jayesh,

    I used your code for my checkbox event. It works great. Could you also suggest how to manipulate with values from drop-down list on selected index changed event? I tried to use the same code you have suggested for checkbox, but I got an error: "Unable to cast object of type 'PanelNamingContainer' to type 'Telerik.Web.UI.GridDataItem ".

    This is my code:

    protected void ddlAssign_SelectedIndexChanged(object sender, DropDownListEventArgs e)
                RadDropDownList ddlAssign = (RadDropDownList)sender;
                GridDataItem item = (GridDataItem)ddlAssign.NamingContainer;

                HiddenField hqc_DateAsigned = (HiddenField)item.FindControl("hqc_DateAsigned");
                hqc_DateAsigned.Value = DateTime.Now.ToShortDateString();

  4. Tsvetomir
    Tsvetomir avatar
    837 posts

    Posted 10 Sep 2018 Link to this post

    Hi Natalya,

    The error you have encountered probably stems from the return type of the NamingContainer. If you have included the RadDropDownList into an EditTemplate, and you are using an Edit mode different than the "InPlace" one, the editable item is of type GridEditFormItem or GridEditFormInsertItem, rather than GridDataItem or GridDataInsertItem. You can find more information here: Accessing Controls in Edit/Insert Mode.

    I suggest you to go over the articles mentioned in the Control inside EditTemplate forum thread.  

    If the issue persists, it would be helpful if you could share the column definition and the code snippet responsible for initializing the RadDropDownList control. Ideally, you can modify one of the samples provided in the forum post from the above and send it back to us.

    Kind regards,
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top