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

ClientSelectColumn: SelectAll(header) event

2 Answers 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jimmy Vithalani
Top achievements
Rank 1
Jimmy Vithalani asked on 04 May 2010, 03:43 PM
Hi All,

I am using 2009 q2 of Telerik. 
I have a grid with client select column and I want to show an alert on uncheck of client select checkbox.
I captured the event deselecing for the checkbox and shown alert.

But the problem is when I do DeSelect All from header check box, I am getting alert for all the rows. I need an event for DeSelectAll so that I can set a flag and do not show alert for all rows, and show only one alert.

Which event I can use for DeSelect All?

Thanks.
Jimmy.

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 05 May 2010, 06:48 AM
Hello Jimmy,

 You can attach an 'onclick' event to the CheckBox control in HeaderItem to show an alert when deselecting all items. And since its is overriding the Header CheckBox behaviour, you need to select/deselect the rows explicitly from client side. Check out the following code and I hope it helps you.

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

C#:
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
  { 
    if (e.Item is GridHeaderItem) 
        { 
            GridHeaderItem headeritem = (GridHeaderItem)e.Item; 
            CheckBox chk = (CheckBox)headeritem["ClientSelectColumn"].Controls[0]; 
            chk.Attributes.Add("onclick""ClientSelect(this);"); 
        } 
  } 

JAVA SCRIPT:
<script type="text/javascript"
function ClientSelect(checkbox)  
  { 
    var grid = $find("<%=RadGrid1.ClientID%>"); 
    var master = grid.get_masterTableView(); 
    if (checkbox.checked == true
     { 
       master.selectAllItems(); 
     } 
    else  
     { 
       alert("You are de-selecting the items"); 
       master.clearSelectedItems() 
     } 
  } 
</script> 

Regards,
Shinu.








0
Jimmy Vithalani
Top achievements
Rank 1
answered on 05 May 2010, 11:01 AM
Hi Shinu,

Thanks for the reply.

Actually last night I tried the same thing, attaching event to ClientSelect checkbox of header in ItemDataBound, and it worked.

Thanks though for the answer, I will mark it.

Jimmy.
Tags
Grid
Asked by
Jimmy Vithalani
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jimmy Vithalani
Top achievements
Rank 1
Share this question
or