Clicking Anywhere in DataGrid Row to Check CheckBox

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!!!
 
E

Eliyahu Goldin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top