Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tooltips for HyperlinkColumn

Status
Not open for further replies.

qtie

Programmer
May 16, 2003
11
US
Hello,
Does anyone know how to set the helper for hyperlink column?

Thanks in advance
Quinn
 
If you're talking ASP.Net here, then you sure can do it by using the TemplateColumn instead:
Code:
<asp:TemplateColumn>
  <ItemTemplate>
    <a href="[URL unfurl="true"]http://msn.com"[/URL] title="whatever">MSN</a>
  </ItemTemplate>
</asp:TemplateColumn>

or:

<asp:TemplateColumn>
  <ItemTemplate>
    <asp:HyperLink Runat=server NavigateUrl="[URL unfurl="true"]http://msn.com"[/URL] Text="MSN" title="whatever" />
  </ItemTemplate>
</asp:TemplateColumn>
 
Thanks LV,
How do I define this at runtime?
 
At a runtime or you just need to bind a value to it, while binding the grid?
 
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink Runat=server NavigateUrl=" Text="MSN" title="whatever" />
</ItemTemplate>
</asp:TemplateColumn>

Can this be done programmatically (in the code behind, and not on the HTML page)?
Thanks.
 
1. To set this attribute through the code, give the HyperLink control an ID and use the ItemDataBound event of the grid.
Code:
<asp:TemplateColumn>
  <ItemTemplate>
    <asp:HyperLink Runat=server ID="myLink" NavigateUrl="[URL unfurl="true"]http://msn.com"[/URL] Text="MSN" />
  </ItemTemplate>
</asp:TemplateColumn>

private void myGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
  if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)
  {
    HyperLink hl = (HyperLink)e.Item.FindControl("myLink");
    if(hl.Attributes["title"] == null)
    {
      hl.Attributes.Add("title", "whatever");
    }
  } 
}

2. If you just need to set the "title" attribute to any value in the recordset that you bind your grid to, you can do it right in html:
Code:
<asp:TemplateColumn>
  <ItemTemplate>
    <asp:HyperLink Runat=server NavigateUrl="[URL unfurl="true"]http://msn.com"[/URL] Text="MSN" title='<%# DataBinder.Eval(Container.DataItem, "fieldName") %>' />
  </ItemTemplate>
</asp:TemplateColumn>
 
the datagrid is defined in the program, not in the HTML. So, I don't have the access to it.
Thanks.
 
Do you mean that the grid is created dynamicaly through the script?
 
Yes, the grid is created dynamically in the codebehind.
So in the HTML, I have just a PlaceHolder.
<asp:placeHolder ID="phDataGrids" Runat="server"></asp:placeHolder>
 
Make sure that you register the ItemDataBound event of the dynamic grid, otherwise the above set up won't work.
Code:
DataGrid myGrid = new DataGrid();
myGrid.ItemDataBound += new DataGridItemEventHandler(myGrid_ItemDataBound);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top