How to add an attribute at table level using GridView

G

Guest

Hi,

I use GridView to populate the date. I want to know how to add an attribute
at table level, for example, onclick="alert('hello');"
so when clicking on anywhere of the table, return message "hello"

Thanks in advance
 
E

Eliyahu Goldin

private void dgSelection_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"] = "alert('hello');";
}

Eliyahu
 
G

Guest

Hi Eliyahu Goldin,
Thanks for your response.
I don't use DataGrid control, but GridView control. Could you provide me the
similar code?



Eliyahu Goldin said:
private void dgSelection_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"] = "alert('hello');";
}

Eliyahu

Li Pang said:
Hi,

I use GridView to populate the date. I want to know how to add an
attribute
at table level, for example, onclick="alert('hello');"
so when clicking on anywhere of the table, return message "hello"

Thanks in advance
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top