Clicking Anywhere in DataGrid Row to Check CheckBox

  • Thread starter Thread starter .NETn00b
  • Start date Start date
N

.NETn00b

Is this possible?

I need to create a multi-select DataGrid, and I cannot use CheckBoxes.
I want the selected rows to appear highlighted. One possible
work-around that occurred to me was to devise my code in such a way as
to allow the user to click anywhere in a DataGrid row, which would
check the CheckBox for that row. Similarly, clicking again in the same
row would un-check the CheckBox. The CheckBoxes in question would be
invisible, and the selected (checked) rows would appear highlighted.
This should give me the appearance I'm looking for (assuming that it
works).

Is this possible? My efforts so far have been unsuccessful.

Is there any chance that someone could provide me with a code snippet
or two, showing how this can be done (if it can be done)?


Thanks!!!
 
Handle ItemDataBound event:

private void dgSelection_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
// provide client-side selection a datagrid row upon clicking
any place on the row.
ListItemType itemType = e.Item.ItemType;
if ((itemType == ListItemType.Pager) ||
(itemType == ListItemType.Header) ||
(itemType == ListItemType.Footer))
{
return;
}
e.Item.Attributes["onclick"] = "onRowClick(this)";
}

Javascript function onRowClick(row) takes a refrence to the clicked row as a
parameter, You can set the row's visual attributes in javascript.

Eliyahu
 
Back
Top