This is a migrated thread and some comments may be shown as answers.

Changing forecolor of GridHyperLinkColumn

5 Answers 316 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vishal
Top achievements
Rank 1
vishal asked on 29 May 2008, 05:30 AM
Hi,
    There must be some simple answer to this, but i am not yet been able to find it. I have a RadGrid and i want to change the forecolor of one of the GridHyperLinkColumn fields. I have tried using ItemStyle-CssClass, ItemStyle-ForeColor but they did not work. Following is the code:

<radG:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" Skin="None" DataSourceID="sdsBlogs" GridLines="None" AutoGenerateColumns="False">

<

MasterTableView DataSourceID="sdsBlogs" DataKeyNames="BLOG_ID">
<
Columns>

<radG:GridHyperLinkColumn DataNavigateUrlField="BLOG_ID" DataNavigateUrlFormatString=http://my.impactwrestling.com/Blog.aspx?ID={0} DataTextField="TITLE" HeaderText="Title" SortExpression="TITLE" UniqueName="TITLE">
</radG:GridHyperLinkColumn

>

<radG:GridHyperLinkColumn DataNavigateUrlField="UserId" DataNavigateUrlFormatString=http://my.impactwrestling.com/MyProfile.aspx?ID={0} DataTextField="UserName" HeaderText="User" SortExpression="UserName" UniqueName="column">
</radG:GridHyperLinkColumn>

<radG:GridBoundColumn DataField="POST_COUNT" HeaderText="# of Comments" SortExpression="POST_COUNT" UniqueName="column1">
</radG:GridBoundColumn>

<radG:GridTemplateColumn HeaderText="Last Post">
<ItemTemplate>
<asp:Label id="lblLocation" runat="server" Text='<%# LastPost((int)Eval("BLOG_ID")) %>'>
</asp:Label>
</ItemTemplate> </radG:GridTemplateColumn>
</
Columns>

<ExpandCollapseColumn Visible="False">
<HeaderStyle Width="19px" />
</ExpandCollapseColumn>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
</
MasterTableView>

</
radG:RadGrid>

I want to make forecolor of Bold n Underlined hyperlink column white

5 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 29 May 2008, 06:19 AM
Hi,

Try the following code snippet in the ItemDataBound event to set the style for the HyperLinkColumn.

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            HyperLink hyplnk = (HyperLink)item["TITLE"].Controls[0]; 
            hyplnk.ForeColor = System.Drawing.Color.Blue; 
            hyplnk.Font.Bold = true
        } 
   } 


Thanks
Shinu.
0
vishal
Top achievements
Rank 1
answered on 30 May 2008, 10:41 AM
Thanks that worked, but can't understand why the properties don't work at design time.

Thanks anyway !!!
0
Chris Ruegsegger
Top achievements
Rank 1
answered on 09 Jun 2008, 02:48 PM
I'm pretty sure that it is a bug.  I am experiencing the same problem.

Chris
0
Pavel
Telerik team
answered on 10 Jun 2008, 11:55 AM
Hi Chris,

The reason that ItemStyle-ForeColor does not work for GridHyperLinkColumn is that the text of the hyperlink is not recognized by the Grid, thus the property is not applied. Another way to set it declaratively is by defining custom css class:

<style type="text/css"
    td.myClass a 
    { 
        colorred
    }     
</style> 

and then setting it for the column like this: ItemStyle-CssClass="myClass".

Greetings,
Pavel
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Ram
Top achievements
Rank 1
answered on 21 Jun 2011, 09:45 AM
Hi
Its working but  I have a requirement where I need to change the forecolor of hyper link on mouse click.
How can I achieve that please help me its urgent.
Tags
Grid
Asked by
vishal
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
vishal
Top achievements
Rank 1
Chris Ruegsegger
Top achievements
Rank 1
Pavel
Telerik team
Ram
Top achievements
Rank 1
Share this question
or