I have a RadGrid that is bound to a SQL database. On the select statement I generate a column that is not in the table. "SELECT '-' as [CheckBox] ...". I then use the ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) event on the RadGrid to add a column of check boxes (one on each row). The user selects certain check boxes (specifying a row) and presses a submit button. How can I read what rows were selected?
I do not use the information to update the database. The database is used for management and does not change. If I can't read the selection is there a different way to do this? Using a RadGrid is just so nice so I would like to keep using that, but I don't need to bind it to a database.
Thanks,
Scott
5 Answers, 1 is accepted

It seems like there is a much easier way to do this. I followed the example at the end of this thread, but the button click event does not indicate that anything was selected. I am on an old version and the post was about a change from v2009 to v2012. Could my problem be a version problem?
(http://www.telerik.com/forums/can-t-get-selected-items-on-server-side-in-a-radgrid-with-checkbox)
Please examine the following article that describe in detail how you can implement server-side selection for items in RadGrid via CheckBox.
Regards,
Viktor Tachev
Telerik

Thank you for that reference. I have looked at it, but I can't see how to read all the selected items on a submit button click. The example and what it referenced did not seem to do that.
I have tried the code below, but it fails on "CheckBox chk = (CheckBox)item["CheckBox1"].Controls[0];". If I try "(dataItem.FindControl("CheckBox1") as CheckBox).Checked" that seems to select everything. The goal is to be able to identify which rows were selected and give me the value of one item in that row.
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
{
CheckBox chk = (CheckBox)item["CheckBox1"].Controls[0];
if (chk.Checked)
{
string value = item["Server"].Text;// access the cell value using ColumnUniqueName
Response.Write("<
script
language
=
'javascript'
>alert('" + value + " .');</
script
>");
}
}
}

The fix was too easy. Just use item.selected.
protected
void
Button1_Click(
object
sender, EventArgs e)
{
foreach
(GridDataItem item
in
WebServerRadGrid.MasterTableView.Items)
{
if
(item.Selected ==
true
)
{
// Do something
}
}
}
I am glad that you have the functionality working.
Thank you for sharing your approach with the community. This can be helpful for someone that is trying to implement similar functionality.
Regards,
Viktor Tachev
Telerik