How to add an attribute at table level using GridView

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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

Back
Top