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

RadGrid with EnablePostBackOnRowClick and GridClientSelectColumn

2 Answers 820 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Iker Llanos
Top achievements
Rank 1
Iker Llanos asked on 21 Apr 2010, 05:04 PM
I have a grid with EnablePostBackOnRowClick = true and GridClientSelectColumn. The problem is that when I try to select various rows with the checkbox in the GridClientSelectColumn a postback is produced and I cannot check the rows.

Is there any way to avoid the postback when selecting the rows through the GridClientSelectColumn?

Thanks in advance 



2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Apr 2010, 06:19 AM

Hello,

I have not experienced the issue that you described. I am able to select the rows eventhough I set 'EnablePostBackOnRowClick' property to true.

If you want to prevent postback when checking/unchecking the checkbox, then one suggestion would be adding GridTemplateColumn with checkbox inside and selecting the row from client side. Here is the example of what I tried.

ASPX:

 
<telerik:GridTemplateColumn HeaderText="CustomerID" UniqueName="CustomerID">  
    <ItemTemplate>  
        <asp:CheckBox ID="CheckBox1" runat="server" />  
    </ItemTemplate>  
</telerik:GridTemplateColumn> 

C#:

 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            CheckBox chk = (CheckBox)item.FindControl("CheckBox1");  
            chk.Attributes.Add("onclick""setStatus('"+item.ItemIndex+"','"+chk.ClientID+"');");  
        }   
    } 

JavaScript:

 
<script type="text/javascript">  
    function setStatus(index, chk) {  
        var grid = $find("<%=RadGrid1.ClientID %>");  
        var mastertableView = grid.get_masterTableView();  
        var checkbox = document.getElementById(chk);  
        if (checkbox.checked) {  
            mastertableView.get_dataItems()[index].set_selected(true);  
        }  
        else {  
            mastertableView.get_dataItems()[index].set_selected(false);  
        }  
    }  
</script> 

-Shinu.

0
Rajiv
Top achievements
Rank 1
answered on 14 Jul 2011, 03:51 PM
//Script 
=============

<script type="text/javascript">
        function StopPostback(sender,args)
        {
            if(//your Condition here)
            {
                sender.ClientSettings.EnablePostBackOnRowClick = false;
return false;
            }
   else
    sender.ClientSettings.EnablePostBackOnRowClick = true
   
        }
            
    </script>


<ClientSettings  EnablePostBackOnRowClick="true" ClientEvents-OnRowClick="StopPostback" ClientEvents-OnRowSelected="StopPostback">
    <Selecting AllowRowSelect="true" />
    </ClientSettings>




Tags
Grid
Asked by
Iker Llanos
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Rajiv
Top achievements
Rank 1
Share this question
or