Checkbox column value in SelectedIndexChanged event

2 posts, 0 answers
  1. Paul
    Paul avatar
    23 posts
    Member since:
    Sep 2006

    Posted 13 Mar 2013 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Mar 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top