Grid: ask for confirmation on select all

2 posts, 0 answers
  1. kiwo
    kiwo avatar
    17 posts
    Member since:
    Apr 2007

    Posted 30 Jul 2009 Link to this post

    Hi.

    I have a GridClientSelectColumn in my grid. The feature I need is the following:
    When SELECT ALL checkbox is checked or unchecked, before it performs the action, confirmation message is required, depending on the status:
    "Are you sure you want to ...(select/deselect all entries)"
    .

    How do I accomplish that?
    Thanks!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Jul 2009 Link to this post

    Hello,

    Try the following code snippet in order to show confirm on checking/unchecking the header checkbox of GridClientSelectColumn.

    ASPX:
     
    <telerik:GridClientSelectColumn UniqueName="Selectcolumn" Text="Select" HeaderText="Select"
    </telerik:GridClientSelectColumn> 

    C#:
     
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        if (e.Item is GridHeaderItem) 
        { 
            GridHeaderItem item = (GridHeaderItem)e.Item; 
            CheckBox chkbx = (CheckBox)item["Selectcolumn"].Controls[0]; 
            chkbx.Attributes.Add("OnClick""showConfirm('"+chkbx.ClientID+"');"); 
        }        

    JavaScript:
     
    <script type="text/javascript"
    function showConfirm(chk) 
        var c = document.getElementById(chk); 
        var grid = $find("<%=RadGrid1.ClientID %>"); 
        if(confirm('Do you want to select/unselect all ...?')) 
        { 
            if(c.checked) 
            { 
                grid.get_masterTableView().selectAllItems(); 
             
            } 
            else 
            { 
                 grid.get_masterTableView().clearSelectedItems(); 
            } 
        } 
        else 
        { 
            c.checked= !c.checked; 
        } 
    </script> 
    Happy coding.. :)

    -Shinu.
Back to Top