Select All Rows Event

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

    Posted 29 Oct 2010 Link to this post

    Hi,

    I have a RadGrid, containing a GridClientSelectColumn.
    I am using server side event processing, and I get the SelectedIndexChanged event whenver a row is clicked or a checkbox is changed.
    However, if the checkbox in the header is clicked, to select / deselect all grid items then I do not receive an event, even though the selected items have obviously changed.
    I am using the lastest set of controls (Sep - Q2 SP2)

    Should I be looking for a different event, or is there another way to get this working?

    Thanks.

    Paul
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 29 Oct 2010 Link to this post

    Hello Paul,

    You can achieve this by accessing the CheckBox in header item and attach a 'CheckedChange' event to the Checkbox. Sample code is given below.

    ASPX:
    <telerik:GridClientSelectColumn UniqueName="GridClientSelectColumn">
    </telerik:GridClientSelectColumn>

    By using following condition inside the OnSelectedIndexChanged event of RadGrid, you can differentiate whether the CheckBox in grid item or the CheckBox in header item is clicked.

    C#:
    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridHeaderItem headerItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0];
        CheckBox headerChkBox = (CheckBox)headerItem["GridClientSelectColumn"].Controls[0];
        if (headerChkBox.Checked)
        {
            // header CheckBox is clicked
        }
        else
        {
           // check box inside Grid row is clicked
        }
         
    }
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridHeaderItem)
        {
            GridHeaderItem headerItem = (GridHeaderItem)e.Item;
            CheckBox headerChkBox = (CheckBox)headerItem["GridClientSelectColumn"].Controls[0];
            headerChkBox.AutoPostBack = true;
            headerChkBox.CheckedChanged += new EventHandler(headerChkBox_CheckedChanged);
        }
    }
     
    void headerChkBox_CheckedChanged(object sender, EventArgs e)
    {
        // Here is your code when header clicked
    }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paul
    Paul avatar
    23 posts
    Member since:
    Sep 2006

    Posted 29 Oct 2010 Link to this post

    Thanks Princy,

    That worked a treat!

    Paul
  5. Thomas Derenthal
    Thomas Derenthal avatar
    38 posts
    Member since:
    Apr 2010

    Posted 04 Nov 2014 Link to this post

    Thank you. I found this yesterday after Googling. This is just what I need.
  6. Thomas Derenthal
    Thomas Derenthal avatar
    38 posts
    Member since:
    Apr 2010

    Posted 04 Nov 2014 Link to this post

    Thank you. This is just what I need,
  7. Thomas Derenthal
    Thomas Derenthal avatar
    38 posts
    Member since:
    Apr 2010

    Posted 04 Nov 2014 Link to this post

    Thank you. This is just what I needed.
  8. Thomas Derenthal
    Thomas Derenthal avatar
    38 posts
    Member since:
    Apr 2010

    Posted 04 Nov 2014 Link to this post

    Multiple replies because the post kept causing a 500 error.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017