how to use oncheckedChaned event into GridCheckboxColumn

12 posts, 0 answers
  1. Dhamodharan
    Dhamodharan avatar
    300 posts
    Member since:
    Sep 2010

    Posted 22 Nov 2010 Link to this post

    Hi,

    I am using GridCheckboxColumn into radgrid in my app. i want oncheckedChaned event. but it is not accept.

     <telerik:GridCheckBoxColumn HeaderText="Internal Change?" UniqueName="chkInternalChange" ForceExtractValue="Always">                                                                                                                                                           
                                    </telerik:GridCheckBoxColumn>

    This is my code. i want how to use oncheckedChaned event.

    It is very very urgent. please help...


    Thanks,
    Dhamu
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Nov 2010 Link to this post

    Hello Dhamu,

    You can attach 'OnCheckedChanged' event to GridCheckBoxColumn from code behind. The following code snippet shows how to attach server side 'OnCheckedChaged' event.

    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                CheckBox chkbox = (CheckBox)item["chkInternalChange"].Controls[0];
                chkbox.Enabled = true;
                chkbox.AutoPostBack = true;
                chkbox.CheckedChanged += new EventHandler(chkbox_CheckedChanged);
            }
        }
        void chkbox_CheckedChanged(object sender, EventArgs e)
        {
            
        }

    If you want it from client side, try the following code snippet.
    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               GridDataItem item = (GridDataItem)e.Item;
               CheckBox chkbox = (CheckBox)item["chkInternalChange"].Controls[0];
               chkbox.Enabled = true;
               chkbox.Attributes.Add("onclick", "oncheckedChaned();");
           }
       }

    Java Script:
    <script type="text/javascript">
        function oncheckedChaned() {
           . . . . .
        }
    </script>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Greg
    Greg avatar
    13 posts
    Member since:
    Sep 2005

    Posted 02 Jan 2013 Link to this post

    Hi Princy how with that approach I can get the other element in the row that contain the checkboxcolumn like a custom ID column?
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Jan 2013 Link to this post

    Hi,

    Try the following code to achieve your scenario.
    C#:
    void chkbox_CheckedChanged(object sender, EventArgs e)
       {
           CheckBox chk = (CheckBox)sender;
           GridDataItem item = (GridDataItem)chk.NamingContainer;
           TableCell cell = (TableCell)item["ID"];
           Response.Write(cell.Text);
       }

    Thanks,
    Princy.
  6. Greg
    Greg avatar
    13 posts
    Member since:
    Sep 2005

    Posted 03 Jan 2013 Link to this post

    I forgot to mention. But I am using I referred to get that using client-side code
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Jan 2013 Link to this post

    Hi,

    Try the following javascript to achieve your scenario.
    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                CheckBox chkbox = (CheckBox)item["check"].Controls[0];
                chkbox.Enabled = true;
                chkbox.Attributes.Add("onClick", "test('" + item.ItemIndex + "');");
            }
        }
    JS:
    function test(index) {
            var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
            var row = masterTable.get_dataItems()[index];
            var cell = masterTable.getCellByColumnUniqueName(row, "Uniquename");
            alert(cell.innerHTML);
    }

    Thanks,
    Princy.
  8. Guillaume
    Guillaume avatar
    2 posts
    Member since:
    Feb 2013

    Posted 01 Mar 2013 Link to this post

    I have try your code but for some reason the code doesn't go to chkbox_CheckedChanged.
    the code do a post back but bypass chkbox_CheckedChanged.

    my code

      protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem item = (GridDataItem)e.Item;
                    CheckBox chkbox = (CheckBox)item["checked"].Controls[0];
                    chkbox.Enabled = true;                
                    chkbox.AutoPostBack = true;
                    chkbox.CheckedChanged += new EventHandler(chkbox_CheckedChanged);
                
                }
            }

          void chkbox_CheckedChanged(object sender, EventArgs e)
            {
                CheckBox chk = (CheckBox)sender;
                GridDataItem item = (GridDataItem)chk.NamingContainer;
                TableCell cell = (TableCell)item["ID"];
                Response.Write(cell.Text);
            } 


    thank for help

  9. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Mar 2013 Link to this post

    Hi,

    Please try attaching the CheckChanged event in the ItemCreated event.

    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                CheckBox chkbox = (CheckBox)item["UniqueName"].Controls[0];
                chkbox.Enabled = true;
                chkbox.AutoPostBack = true;
                chkbox.CheckedChanged += new EventHandler(chkbox_CheckedChanged);
            }
        }

    Thanks,
    Shinu.

  10. Guillaume
    Guillaume avatar
    2 posts
    Member since:
    Feb 2013

    Posted 04 Mar 2013 Link to this post

    stupid I'm !

    thank
  11. Preeti
    Preeti avatar
    8 posts
    Member since:
    Jan 2014

    Posted 03 Jan 2014 Link to this post

    Hello
     

    I'm using your code but it gives an error that 

    The type or namespace name 'GridDataItem' could not be found (are you missing a using directive or an assembly reference?)
    hw to solve this....Did I miss any namespace below is my code...


    protected void gvDetails_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                CheckBox chkbox = (CheckBox)item["chkInternalChange"].Controls[0];
                chkbox.Enabled = true;
                chkbox.AutoPostBack = true;
                chkbox.CheckedChanged += new EventHandler(chkbox_CheckedChanged);
            }
        }
  12. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Jan 2014 Link to this post

    Hi Preeti,

    Please try including 'Telerik.Web.UI' namespace in your CS page.

    Thanks,
    Princy
  13. Rajesh Duraisamy
    Rajesh Duraisamy avatar
    9 posts
    Member since:
    Jul 2012

    Posted 26 May Link to this post

    I am creating the GridCheckBoxColumn in the NeedDataSource but i am unable to reach the cbxReader_CheckedChanged event.

    The checkbox is also enabled and tooltip also displaying.

    Also tried the same in grRemainderMappings_ItemDataBound but not helped.

    Can you please help to fix the issue.

    protected void grRemainderMapping_ItemCreated(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem dItem = e.Item as GridDataItem;
                    for (int i = 3; i < dt.Columns.Count; i++)
                    {
                        CheckBox chkbox = (CheckBox)dItem[dt.Columns[i].ColumnName].Controls[0];
                        chkbox.ToolTip = "Select this template";
                        chkbox.Enabled = true;
                        chkbox.AutoPostBack = true;
                        chkbox.CheckedChanged += new EventHandler(cbxReader_CheckedChanged);
                    }
                }           
            }
    protected void grRemainderMappings_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
            {
                 
                try
                {
    dt = Proxy.DmAppointments.GetPracticeAppointmentReminderTemplatesMapping(this.selectedPracticeId);
     
                    for (int j = 3; j < dt.Columns.Count; j++)
                    {
                        ChangeColumnDataType(dt, dt.Columns[j].ColumnName, typeof(bool));
                    }
                    foreach (DataColumn column in dt.Columns)
                    { if (column.ColumnName != "AppointmentReasonId" && column.ColumnName != "ReasonCode" && column.ColumnName != "Description")
                        {
                            GridCheckBoxColumn checkBoxColumn = new GridCheckBoxColumn();
                            this.grRemainderMappings.MasterTableView.Columns.Add(checkBoxColumn);
                            checkBoxColumn.UniqueName = column.ColumnName;
                            checkBoxColumn.DataField = column.ColumnName;
                            checkBoxColumn.HeaderText = column.ColumnName;
                            checkBoxColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                        }
                    }
     
                    this.grRemainderMappings.DataSource = dt;
                    this.grRemainderMappings.MasterTableView.EditMode = GridEditMode.InPlace;
                }
                catch (Exception ex)
                {                
                }
            }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017