Friday, May 21, 2004

For D8: Click anywhere & select with a web grid

I've converted Karl Moore's code for clicking anywhere on a web grid to select an item, and fixed a bug so that clicking on the currently selected row doesn't cause dramas. Here it is:


procedure TWebForm1.DBWebGrid1_ItemDataBound(
sender: System.Object;
e: System.Web.UI.WebControls.DataGridItemEventArgs);
var
btnSelect: Button;
begin
If (e.Item.ItemType = ListItemType.Header) Or
(e.Item.ItemType = ListItemType.Footer) Or
(e.Item.ItemType = ListItemType.Pager) Then
Exit;

If (e.Item.Cells[0].Controls.Count > 0) Then
begin
If e.Item.Cells[0].Controls[0] Is Button Then
begin
btnSelect := e.Item.Cells[0].Controls[0] as Button;
if (sender is DataGrid) and
(e.Item.itemindex = (sender as DataGrid).SelectedIndex) then
e.Item.Attributes['onclick'] := ''
else
e.Item.Attributes['onclick'] :=
Page.GetPostBackClientHyperlink(btnSelect, '');
End;
End;
End;

0 Comments:

Post a Comment

<< Home