Is it possible to allow client side row selection but for only some rows?
I want the client side selection with the checkbox selection column but I only want some of the rows to be selectable. For example every second row has the tick box and can be selected and the others do not have the checkbox and cannot be selected.
Clayton
8 Answers, 1 is accepted

Try the following code snippet for hiding the checkbox for particlar rows based on condition.
ASPX:
<telerik:radgrid id="RadGrid1" runat="server" allowmultirowselection="True" datasourceid="SqlDataSource1"> |
<MasterTableView DataSourceID="SqlDataSource1" AutoGenerateColumns="False"> |
<Columns> |
<telerik:GridClientSelectColumn UniqueName="Select"></telerik:GridClientSelectColumn> |
. . . |
</Columns> |
</MasterTableView> |
<ClientSettings> |
<Selecting AllowRowSelect="True"></Selecting> |
</ClientSettings> |
</telerik:radgrid> |
CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridDataItem) |
{ |
GridDataItem item = (GridDataItem)e.Item; |
if(item.ItemIndex == 1) // Condition |
{ |
(item["Select"].Controls[0] as CheckBox).Visible = true; |
} |
else |
{ |
(item["Select"].Controls[0] as CheckBox).Visible = false; |
} |
} |
} |
Thanks,
Princy.

Thanks for the reply. I have done something very similar to this and it mostly works. I can now select only the rows I want availabel for selection.
But I have a problem with the select all rows check box at the top of the Select column. If I tick it then all rows that can be selecetd are selected. But if I tick it again it will not deselect all rows. How can I get the deselect all to work?
Clayton
I think that the implementation from the following code library thread can help you implement the select all/deselect all functionality for the GridClientSelectColumn you are after:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/gridclientselectcolumn-select-all-rows-with-enabled-check-boxes-only.aspx
Feel free to modify/extend the code to meet your custom requirements.
Kind regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.

I tried the technique here:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/gridclientselectcolumn-select-all-rows-with-enabled-check-boxes-only.aspx
but get errors (is there a newer post on how to have a checkbox that selects all rows whose select box is visible?):
Error 4 Type 'Telerik.Web.UI.GridClientSettings' does not have a public property named 'ApplyStylesOnClient'. D:\www\bf_2006\SNet\BalanceMultipleSCS.aspx 110
Error 5 Type 'Telerik.Web.UI.RadGrid' does not have a public property named 'Selecting'. D:\www\bf_2006\SNet\BalanceMultipleSCS.aspx 111
Error 6 Type 'Telerik.Web.UI.RadGrid' does not have a public property named 'ClientEvents'. D:\www\bf_2006\SNet\BalanceMultipleSCS.aspx 112
Error 7 Content ('</Selecting> </ClientSettings>') does not match any properties within a 'Telerik.Web.UI.RadGrid', make sure it is well-formed. D:\www\bf_2006\SNet\BalanceMultipleSCS.aspx 109
Here is the code:
<%@ Page Language="VB" MasterPageFile="~/WithMenu.master" AutoEventWireup="false" CodeFile="BalanceMultipleSCS.aspx.vb" Inherits="SNet_BalanceMultipleSCS" Title="BalanceMultipleSCS" %>
<%@ Register TagPrefix="rad" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<asp:Content ID="Content1" ContentPlaceHolderID="content" Runat="Server">
<script type="text/javascript">
var selecting;
var grid;
var checkBox;
function pageLoad() {
checkBox = $get($get('HiddenField1').value)
$addHandler(checkBox, "click", onclickHandler);
grid = $find('<%=RadGrid1.ClientID %>')
// access the grid items, so that they are created and we can use grid selected items count is calculated correctly, bug -- will be fixed in Q1
var tmp = grid.get_masterTableView().get_dataItems().length;
if (parseInt($get('HiddenField2').value, 10) + grid.get_masterTableView().get_selectedItems().length == grid.get_masterTableView().get_dataItems().length) {
checkBox.checked = true;
}
}
function onclickHandler() {
if (grid.get_masterTableView().get_selectedItems().length > 0) {
checkBox.checked = true;
}
else {
checkBox.checked = false;
}
}
var selecting = true;
function RowSelecting(sender, args) {
var id = args.get_id();
var inputCheckBox = $get(id).getElementsByTagName("input")[0];
if (!inputCheckBox || inputCheckBox.disabled) {
//cancel selection for disabled rows
args.set_cancel(true);
}
// if no more unselected enabled rows left - check the header checkbox
else if (parseInt($get('HiddenField2').value, 10) + grid.get_masterTableView().get_selectedItems().length + 1 == grid.get_masterTableView().get_dataItems().length) {
checkBox.checked = true;
}
}
function RowDeselecting(sender, args) {
checkBox.checked = false;
}
</script>
<table width="1200">
<tr>
<td>
<asp:Label ID="lblErr" runat="server" Font-Bold="True"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:CheckBox ID="chkYes" runat="server" Width="800px" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblYesMsg" runat="server" Visible="False">To re-balance now, check this box & boxes of SCSs to re-balanced, click 'Balance Selected SCS'</asp:Label>
</td>
</tr>
<tr>
<td>
<table style="width: 100%">
<tr>
<td style="width: 72px">
<asp:DropDownList ID="ddlistTierBox" runat="server" AutoPostBack="True">
</asp:DropDownList>
</td>
<td style="width: 71px">
Tier</td>
<td style="width: 294px">
Click 'Refresh' below to update balance status:</td>
<td>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<rad:RadGrid ID="RadGrid1" AllowMultiRowSelection="true" Skin="WebBlue" runat="server" width="100%"
AutoGenerateColumns="False" OnItemDataBound="RadGrid1_ItemDataBound" OnItemCommand="RadGrid1_ItemCommand" DataSourceID="ObjDataSourceGetSCS_Status">
<ClientSettings>
<Selecting AllowRowSelect="true" />
</ClientSettings>
<MasterTableView CommandItemDisplay="Top" DataKeyNames="SCS_ID" DataSourceID="ObjDataSourceGetSCS_Status"
AutoGenerateColumns="False" Width="100%">
<CommandItemTemplate>
<div style="padding: 10px 0px;">
<asp:LinkButton ID="LinkButton1" Font-Size="X-Small" OnClientClick="javascript:return confirm('Balance selected SCS?')"
runat="server" CommandName="BM" CausesValidation="false" ><img style="border:0px;vertical-align:middle;" alt="" src="../Images/Balance.png" /> Balance Selected SCS</asp:LinkButton>
<asp:LinkButton ID="LnkRef" Font-Size="X-Small" runat="server" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="../Images/Refresh.gif" /> Refresh</asp:LinkButton>
</div>
</CommandItemTemplate>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn Visible="False" Resizable="False">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<rad:GridClientSelectColumn HeaderStyle-Width="40px" UniqueName="SelectColumn" />
<rad:GridBoundColumn DataField="SCS_ID" HeaderText="SCS_ID" UniqueName="SCS_ID" ReadOnly="true"
Visible="false">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="SCSName" HeaderText="SCS" UniqueName="SCSName"
ReadOnly="true">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="MsgCannotBalAsync" HeaderText="" UniqueName="MsgCannotBalAsync"
ReadOnly="true">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="BasicObjectiveDaysOfSupply" HeaderText="SCSO" UniqueName="Obj">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="ACAP" HeaderText="ACAP" UniqueName="ACAP">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="UseACAP_RegardlessOfShortageMsg" HeaderText="UseAll?" UniqueName="UseAllACAP_YN">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="sDateBalanced" HeaderText="Balanced" UniqueName="Balanced"
DataFormatString="{0:MM/dd/h:mm tt}">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="DateInventoryUpdatedAnyMethod" HeaderText="Inventory"
UniqueName="Inv" DataFormatString="{0:MM/dd/h:mm tt}">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="ForecastUpdatedAnyMethod" HeaderText="Forecast" UniqueName="Forecast"
DataFormatString="{0:MM/dd/h:mm tt}">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="DateSCS_Updated" HeaderText="SCS" UniqueName="SCSu"
DataFormatString="{0:MM/dd/h:mm tt}">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="DateSCS_SKU_Updated" HeaderText="SCS_SKU" UniqueName="SCS_SKU"
DataFormatString="{0:MM/dd/h:mm tt}">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="ReadyToBal" HeaderText="ReadyToBal" UniqueName="ReadyToBal" Visible="false">
</rad:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings ApplyStylesOnClient="True">
<Selecting AllowRowSelect="True"></Selecting>
<ClientEvents OnRowSelecting="RowSelecting" />
</ClientSettings>
</rad:RadGrid>
<asp:ObjectDataSource ID="ObjDataSourceGetSCS_Status" runat="server" TypeName="SCS_linq"
SelectMethod="GetSCS_BalEntities" EnablePaging="false">
<SelectParameters>
<asp:ControlParameter Name="iSNet_ID" ControlID="lblSNet_ID" PropertyName="Text" />
<asp:ControlParameter Name="sTier" ControlID="lblTierSelected" PropertyName="Text" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblSNet_ID" runat="server" Visible="False"></asp:Label>
<asp:Label ID="lblSNet_Name" runat="server" Visible="False"></asp:Label>
<asp:Label ID="lblPersonFullName" runat="server" Visible="False"></asp:Label>
<asp:Label ID="lblTierSelected" runat="server" Visible="False"></asp:Label>
<asp:Label ID="lblBalCmdGiven" runat="server" Visible="False"></asp:Label>
</td>
</tr>
</table>
</asp:Content>

So as a work around I tried the javascript from this post:
http://www.telerik.com/community/forums/aspnet-ajax/listbox/client-click-event.aspx
but it did not work.
code below:
<%
@ Page Language="VB" MasterPageFile="~/WithMenu.master" AutoEventWireup="false" CodeFile="BalanceMultipleSCS.aspx.vb" Inherits="SNet_BalanceMultipleSCS" Title="BalanceMultipleSCS" %>
<%
@ Register TagPrefix="rad" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<
asp:Content ID="Content1" ContentPlaceHolderID="content" Runat="Server">
<
script type="text/javascript">
function clickFirstItem() {
var list = $find("<%= ddlistTierBox.ClientID %>");
var item = list.getItem(2);
item.select();
var item = list.getItem(0);
item.select();
}
</
script>
<
table width="1200">
<
tr>
<
td>
<
asp:Label ID="lblErr" runat="server" Font-Bold="True"></asp:Label>
</
td>
</
tr>
<
tr>
<
td>
<
asp:CheckBox ID="chkYes" runat="server" Width="800px" />
</
td>
</
tr>
<
tr>
<
td>
<
asp:Label ID="lblYesMsg" runat="server" Visible="False">To re-balance now, check this box & boxes of SCSs to re-balanced, click 'Balance Selected SCS'</asp:Label>
</
td>
</
tr>
<
tr>
<
td>
<
table style="width: 100%">
<
tr>
<
td style="width: 72px">
<
asp:DropDownList ID="ddlistTierBox" runat="server" AutoPostBack="True">
</
asp:DropDownList>
</
td>
<
td style="width: 71px">
Tier
</td>
<
td style="width: 294px">
Click
'Refresh' below to update balance status:</td>
<
td>
</td>
</
tr>
</
table>
</
td>
</
tr>
<
tr>
<
td>
<
rad:RadGrid ID="RadGrid1" AllowMultiRowSelection="true" Skin="WebBlue" runat="server" width="100%"
AutoGenerateColumns
="False" OnItemDataBound="RadGrid1_ItemDataBound" OnItemCommand="RadGrid1_ItemCommand" DataSourceID="ObjDataSourceGetSCS_Status">
<
ClientSettings>
<
Selecting AllowRowSelect="true" />
</
ClientSettings>
<
MasterTableView CommandItemDisplay="Top" DataKeyNames="SCS_ID" DataSourceID="ObjDataSourceGetSCS_Status"
AutoGenerateColumns
="False" Width="100%">
<
CommandItemTemplate>
<
div style="padding: 10px 0px;">
<
asp:LinkButton ID="LinkButton1" Font-Size="X-Small" OnClientClick="javascript:return confirm('Balance selected SCS?')"
runat
="server" CommandName="BM" CausesValidation="false" ><img style="border:0px;vertical-align:middle;" alt="" src="../Images/Balance.png" /> Balance Selected SCS</asp:LinkButton>
<asp:LinkButton ID="LnkRef" Font-Size="X-Small" runat="server" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="../Images/Refresh.gif" /> Refresh</asp:LinkButton>
</
div>
</
CommandItemTemplate>
<
RowIndicatorColumn Visible="False">
<
HeaderStyle Width="20px"></HeaderStyle>
</
RowIndicatorColumn>
<
ExpandCollapseColumn Visible="False" Resizable="False">
<
HeaderStyle Width="20px"></HeaderStyle>
</
ExpandCollapseColumn>
<
Columns>
<
rad:GridClientSelectColumn HeaderStyle-Width="40px" UniqueName="SelectColumn" />
<
rad:GridBoundColumn DataField="SCS_ID" HeaderText="SCS_ID" UniqueName="SCS_ID" ReadOnly="true"
Visible
="false">
</
rad:GridBoundColumn>
<
rad:GridBoundColumn DataField="SCSName" HeaderText="SCS" UniqueName="SCSName"
ReadOnly
="true">
</
rad:GridBoundColumn>
<
rad:GridBoundColumn DataField="MsgCannotBalAsync" HeaderText="" UniqueName="MsgCannotBalAsync"
ReadOnly
="true">
</
rad:GridBoundColumn>
<
rad:GridBoundColumn DataField="BasicObjectiveDaysOfSupply" HeaderText="SCSO" UniqueName="Obj">
</
rad:GridBoundColumn>
<
rad:GridBoundColumn DataField="ACAP" HeaderText="ACAP" UniqueName="ACAP">
</
rad:GridBoundColumn>
<
rad:GridBoundColumn DataField="UseACAP_RegardlessOfShortageMsg" HeaderText="UseAll?" UniqueName="UseAllACAP_YN">
</
rad:GridBoundColumn>
<
rad:GridBoundColumn DataField="sDateBalanced" HeaderText="Balanced" UniqueName="Balanced"
DataFormatString
="{0:MM/dd/h:mm tt}">
</
rad:GridBoundColumn>
<
rad:GridBoundColumn DataField="DateInventoryUpdatedAnyMethod" HeaderText="Inventory"
UniqueName
="Inv" DataFormatString="{0:MM/dd/h:mm tt}">
</
rad:GridBoundColumn>
<
rad:GridBoundColumn DataField="ForecastUpdatedAnyMethod" HeaderText="Forecast" UniqueName="Forecast"
DataFormatString
="{0:MM/dd/h:mm tt}">
</
rad:GridBoundColumn>
<
rad:GridBoundColumn DataField="DateSCS_Updated" HeaderText="SCS" UniqueName="SCSu"
DataFormatString
="{0:MM/dd/h:mm tt}">
</
rad:GridBoundColumn>
<
rad:GridBoundColumn DataField="DateSCS_SKU_Updated" HeaderText="SCS_SKU" UniqueName="SCS_SKU"
DataFormatString
="{0:MM/dd/h:mm tt}">
</
rad:GridBoundColumn>
<
rad:GridBoundColumn DataField="ReadyToBal" HeaderText="ReadyToBal" UniqueName="ReadyToBal" Visible="false">
</
rad:GridBoundColumn>
</
Columns>
</
MasterTableView>
</
rad:RadGrid>
<
asp:ObjectDataSource ID="ObjDataSourceGetSCS_Status" runat="server" TypeName="SCS_linq"
SelectMethod
="GetSCS_BalEntities" EnablePaging="false">
<
SelectParameters>
<
asp:ControlParameter Name="iSNet_ID" ControlID="lblSNet_ID" PropertyName="Text" />
<
asp:ControlParameter Name="sTier" ControlID="lblTierSelected" PropertyName="Text" />
</
SelectParameters>
</
asp:ObjectDataSource>
</
td>
</
tr>
<
tr>
<
td>
<
asp:Label ID="lblSNet_ID" runat="server" Visible="False"></asp:Label>
<
asp:Label ID="lblSNet_Name" runat="server" Visible="False"></asp:Label>
<
asp:Label ID="lblPersonFullName" runat="server" Visible="False"></asp:Label>
<
asp:Label ID="lblTierSelected" runat="server" Visible="False"></asp:Label>
<
asp:Label ID="lblBalCmdGiven" runat="server" Visible="False"></asp:Label>
</
td>
</
tr>
</
table>
</
asp:Content>
I assume that you are using the ASP.NET AJAX version of the grid. Therefore, please use the sample project from the code library with _Web_UI suffix - the other is for the ASP.NET Classic version of the control. Thus no error should be generated.
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

You are correct. Can you recommend a specific example project
So I tried examples with _Web_UI suffix:
GridClientSelectionOnEnabledCheckBoxes_SyncHeaderCheckBox_Web.UI.zip
GridClientSelectionOnEnabledCheckBoxes_WebUI.zip
mentioned here:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/gridclientselectcolumn-select-all-rows-with-enabled-check-boxes-only.aspx
I still get errors on:
<ClientSettings ApplyStylesOnClient="True">
<Selecting AllowRowSelect="True"></Selecting>
<ClientEvents OnRowSelecting="RowSelecting" OnRowDeselecting="RowDeselecting" />
</ClientSettings>
Steve
Remove the ClentSettings -> ApplyStylesOnClient property from your grid definition since it is available only in the ASP.NET predecessor of RadGrid for ASP.NET.
Kind regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.