Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

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

by:Hamed Zaghaghi
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

571 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