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

Checkbox column value in SelectedIndexChanged event

1 Answer 183 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 13 Mar 2013, 02:35 PM
Hi,

I have a grid, which contains some Checkbox columns.
In the SelectedIndexChanged event on the server, I am trying to read the checked status of the checkbox columns.
I have tried several different variations to get this, but I seem to be banging my head against a wall.
I'm sure this is fairly striaght forward, but I can't see where the problem lies, and I can't find an example of what I am trying to do.

Below are the different things I have tried - all of which give me a Null value exception.

All suggestions greatly appreciated.

Attached = ((System.Web.UI.WebControls.CheckBox)BaysGrid.SelectedItems[0].FindControl("bgAttached")).Checked;
 
Attached = ((System.Web.UI.WebControls.CheckBox)(BaysGrid.MasterTableView.GetSelectedItems()[0].Controls[0].Controls[0])).Checked;
 
Attached = ((System.Web.UI.WebControls.CheckBox)(BaysGrid.MasterTableView.GetSelectedItems()[0].FindControl("bgAttached"))).Checked;
 
Attached = Convert.ToBoolean(BaysGrid.SelectedItems[0].Cells[5].Text);

Grid name is BaysGrid, Markup for the specific column is:
<telerik:GridCheckBoxColumn DataField="bAttached" DataType="System.Boolean"
  FilterControlAltText="Filter bgAttached column" HeaderText="Attach"
  UniqueName="bgAttached">
  <HeaderStyle Width="40px" />
</telerik:GridCheckBoxColumn>



Thanks

Paul

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Mar 2013, 04:15 AM
Hi,

Try the following code to achieve your scenario.
C#:
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
        foreach (GridDataItem item in RadGrid1.SelectedItems)
        {
            CheckBox chk = (CheckBox)item["bgAttached"].Controls[0];
            if (chk.Checked)
            {
            }
        }
 }

Thanks,
Shinu
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or