datagrid - accessing data in a row

  • Thread starter Thread starter gregoryenelson
  • Start date Start date
G

gregoryenelson

Hi.

I am sitting here in a company with many people, but no othe
programmers least of all asp.net ones.

I have created a 'view' form on the INTRAnet, where many lines ar
displayed in a datagrid (SeLECT statement built in code and the Datase
bound to datagrid).

I just need to allow the user to click a row, whereupon I take the ke
from a field in that row and open up a Detail page.

I cannot find a way. OK, there is clientside and serverside scope, bu
there must be a way to do this.

Possible?

Help greatly appreciated.

Gre


-
gregoryenelso
 
Greg,

On server side use ItemDataBound event to setup a javasript onclick event
handler for every cell in the row. Example:

private void dgList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if ((itemType == ListItemType.Pager) ||
(itemType == ListItemType.Header) ||
(itemType == ListItemType.Footer))
{
return;
}
e.Item.Attributes["onclick"] = "onRowClick(this)";
}

On client side in onRowClick(this) change the row visual properties to make
it visualy selected and save the key column value in a variable. If the grid
doesn't show the key value, pass it in an invisible column. When you need to
open the detail page, do it with showModalDialog call and pass the saved key
as a parameter.

Eliyahu
 
Back
Top