Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Dynamically set attributes (on ItemDataBound evet ) on a link button that is on a GridView
 

Dynamically set attributes (on ItemDataBound evet ) on a link button that is on a GridView

Hi,

I wanted to set attribues of a link button on the ItemDataBound event of a GridView. There the Link button is under a Item template of the GridView.

This is what how I tried in the code behind.

protected

 

void gridViewRowDataBound(object sender, ListViewItemEventArgs e)
{
  if (e.Item.ItemType == ListViewItemType.DataItem){
  LinkButton portalUrl = (LinkButton)e.Item.FindControl("portalUrl");
  object pwdataRowObject = ((ListViewDataItem)e.Item).DataItem;
  DataRowView pwdataRowView = (DataRowView)pwdataRowObject;

  portalUrl.Attributes.Add(

"href", pwdataRowView["PortalURL"].ToString());
  portalUrl.Attributes.Add(
"src", "/images/iconNav.jpg");
  }
}

Called this method on the GridView method":

<

 

asp:GridView ID="testGridView" runat="server" AutoGenerateColumns="False" CssClass="myTable1" Width="439px" OnRowDataBound="gridViewRowDataBound">


Issue: This compiles OK, but when this executes getting error saying "Unknown Error", please advice me

NSJ SL  Wednesday, October 07, 2009 10:09 AM
Hi NSJ SL,

Based on my understanding, the issue is related to Asp.Net, so you need to post in this forum:
http://forums.asp.net/18.aspx

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  26 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• modifying the data in Strongly typed dataset before updating to the database
• Unconventional use of Tableadapters
• Color for separator lines in DataGridView
• ComboBox In DataGridView Event. SelectedIndexChange
• Highligting (coloring) current (selected) row in DataGridView
• what is the procedure to insert the chackbox in the datagrid column?
• BindingNavigator and events?
• Databinding and the TemplateField Element.
• Instantiating a datagrid fill
• Disabling DataGrid cell highlight