RadGrid for ASP .NET version
RadControls for ASP .NET AJAX version |
Q4 2006 SP2 and later
2008.1.415 and later |
.NET version |
2.0 and later
|
Visual Studio version |
2005 and later
|
Programming language |
C#, Javascrpt
|
Browser support |
all supported by RadGrid for ASP .NET
all browsers supported by RadControls for ASP .NET AJAX
|
To convert code from posted projects |
Telerik online converter |
PROJECT DESCRIPTION
In some particular cases you may need to disallow selection for part of the rows in grid having GridClientSelectColumn. Wiring the
ItemCreated or
ItemDataBound events and disabling the checkbox in that GridClientSelectColumn solves the problem partially. Still if the checkbox in the grid header is checked -- all grid items become selected.
The attached project uses a hidden input to send the indexes of the non-selectable items to the client. On the client these values are loaded into an array. Then inside
RowSelecting client event handler of the grid a javascript function is executed to check if the index of the row being selected is in the list. If that is true the event has been cancelled.
Below is the essential part of the code:
protected void RadGrid1_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e) |
{ |
if (e.Item is GridDataItem) //Your condition goes here |
{ |
((e.Item as GridDataItem)["Select"].Controls[1] as CheckBox).Enabled = false; |
Sel.Value += e.Item.ItemIndex.ToString() + ":"; |
} |
} |
<script type="text/javascript"> |
var a = Array; |
window.onload = function () |
{ |
var inp = document.getElementById('Sel'); |
var data = inp.value; |
if(data != "") |
{ |
var rowsData = data.split(":"); |
var i=0; |
while(typeof(rowsData[i]) != "undefined") |
{ |
if (rowsData[i] != "") |
{ |
a[i] = rowsData[i]; |
} |
i++; |
} |
} |
} |
function Selecting (row) |
{ |
var i = 0; |
while(typeof(a[i]) != "undefined") |
{ |
if (a[i++] == row.Index) |
{ |
return false; |
} |
} |
} |
</script> |
|