Change style of asp:hyperlink inside datagrid ItemTemplate (C#)

Posted on 2005-03-30
Medium Priority
Last Modified: 2008-01-16
I have a datagrid that uses mostly asp:BoundColumn to display column data.  However I have one column that uses an ASP:ItemTemplate to build an asp:hyperlink:

      <asp:HyperLink id=HyperLink1 CssClass="gConentSection" runat="server" Target="_blank" Text='<%# DataBinder.Eval(Container.DataItem, "ItemNo") %>' NavigateUrl='<%# GetDiscussionUrl(DataBinder.Eval(Container.DataItem, "ItemId")) %>' />

I am trying to change the font style of the Text attribute of this hyperlin based on the value from another bound column (e.Items.Cells[9]).

I am able to change the change font text to all my other bound columns (cells 1-3), using my function in OnItemDataBound, but I cannot change the font of cell 0 that contains my asp:Hyperlink.  HOW TO DO THIS????  Here is my code.  I have commented out my unsuccessful attempts at change th font in e.items.cell[0].

protected void ItemsGrid_DataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
//If the data exists, navigate through each cell
     for (int x=0;x < e.Item.Cells.Count  -1;x++)
     //Check for the ListItemType.Item or ListItemType.AlternatingItem
      if ((e.Item.ItemType == ListItemType.Item )|| (e.Item.ItemType == ListItemType.AlternatingItem))
               if(e.Item.Cells[9].Text == "0")
            //e.Item.Cells[0].ControlStyle.Font.Bold = true; << DOES NOT WORK
            //e.Item.Cells[0].Font.Bold = true; << DOES NOT WORK

                                //THESE WORK BECAUSE THEY ARE BOUND COLUMNS
            e.Item.Cells[1].Font.Bold = true;
            e.Item.Cells[2].Font.Bold = true;
            e.Item.Cells[3].Font.Bold = true;

Question by:jschertz
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

imperial_p79 earned 1000 total points
ID: 13664543
add all your style in a css file and then you can set it this way


Hope this helps!

Author Comment

ID: 13664690
Worked like a charm!
Thanks for the quick response.

Expert Comment

ID: 13664755
you must first find the control, by FindControl Function , and then Cast it to Hyperlink as follow:

if you named the HyperlinkTemplate to "hl" then use this code:
((HyperLink)e.Item.Cells[0].FindControl("hl")).Font = //what you want

have a good programming day;

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question