This is a migrated thread and some comments may be shown as answers.

how to use oncheckedChaned event into GridCheckboxColumn

11 Answers 560 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dhamodharan
Top achievements
Rank 1
Dhamodharan asked on 22 Nov 2010, 02:59 PM
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

11 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Nov 2010, 06:52 AM
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.
0
Greg
Top achievements
Rank 1
answered on 02 Jan 2013, 09:58 PM
Hi Princy how with that approach I can get the other element in the row that contain the checkboxcolumn like a custom ID column?
0
Princy
Top achievements
Rank 2
answered on 03 Jan 2013, 04:46 AM
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.
0
Greg
Top achievements
Rank 1
answered on 03 Jan 2013, 02:19 PM
I forgot to mention. But I am using I referred to get that using client-side code
0
Princy
Top achievements
Rank 2
answered on 04 Jan 2013, 04:49 AM
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.
0
Guillaume
Top achievements
Rank 1
answered on 01 Mar 2013, 10:06 PM
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

0
Shinu
Top achievements
Rank 2
answered on 02 Mar 2013, 03:32 AM
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.

0
Guillaume
Top achievements
Rank 1
answered on 04 Mar 2013, 02:52 PM
stupid I'm !

thank
0
Preeti
Top achievements
Rank 1
answered on 03 Jan 2014, 06:39 AM
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);
        }
    }
0
Princy
Top achievements
Rank 2
answered on 03 Jan 2014, 07:22 AM
Hi Preeti,

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

Thanks,
Princy
0
rajesh
Top achievements
Rank 1
answered on 26 May 2016, 06:36 AM

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)
            {                
            }
        }
Tags
Grid
Asked by
Dhamodharan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Greg
Top achievements
Rank 1
Guillaume
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Preeti
Top achievements
Rank 1
rajesh
Top achievements
Rank 1
Share this question
or