Click anywhere in a row....

U

UJ

Is there any way to tell when a user clicks anywhere in a row? The only way
I can think to do it is to make each column a link with a button and use the
text as the value I want displayed.

TIA.
 
E

Eliyahu Goldin

There is a number of ways. The easiest one (C# syntax):

Add a hidden button column:

<asp:datagrid id=myGrid runat="server" AutoGenerateColumns="False"
OnItemDataBound="myGrid_ItemDataBound" >
<Columns>
<asp:ButtonColumn ButtonType="LinkButton" CommandName="Select"
Visible="False"></asp:ButtonColumn>
<asp:BoundColumn DataField="user_nm" HeaderText="Logon
Name"></asp:BoundColumn>
<asp:BoundColumn DataField="last_nm" HeaderText="Last
Name"></asp:BoundColumn>
<asp:BoundColumn DataField="first_nm" HeaderText="First
Name"></asp:BoundColumn>
</Columns>
</asp:datagrid>

and setup an ItemDataBound event handler:

protected void myGrid_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;
}
LinkButton button = (LinkButton) e.Item.Cells[0].Controls[0];
e.Item.Attributes["onclick"] = this.GetPostBackClientHyperlink
(button, "");
}

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top