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

[Solved] Data format issue for hyperlink column

5 Answers 191 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve LaForge
Top achievements
Rank 1
Steve LaForge asked on 15 Apr 2009, 09:33 PM
I have a grid defined as below.  I want all of the columns to have white text, with alternating shades of green for the rows.  Everything works fine except that the single hyperlink column that I have uses the default foreground color (black).  I've tried setting the color on both the grid ItemStyle (which worked for everything else) and then I tried setting the attribute on the GridHyperLinkColumn, which still did not work.

<telerik:RadGrid ID="gridResults" runat="server" EnableEmbeddedSkins="True" Skin="Default"   
            width="100%" GridLines="None" AutoGenerateColumns="False"   
            StatusBarSettings-ReadyText="Click on a row to see the device details">  
            <SelectedItemStyle BackColor="#BE7F3F" /> 
            <HeaderStyle Font-Size="8pt" HorizontalAlign="Center" VerticalAlign="Bottom" /> 
            <ItemStyle ForeColor="White" Font-Size="8pt" BackColor="#9CAC57" HorizontalAlign="Center" VerticalAlign="Top" /> 
            <AlternatingItemStyle ForeColor="White" Font-Size="8pt" BackColor="#B1C363" HorizontalAlign="Center" VerticalAlign="Top" /> 
            <HeaderContextMenu EnableEmbeddedSkins="False"></HeaderContextMenu> 
            <MasterTableView DataKeyNames="FacilityID,ControlNum,EquipActive" GridLines="None" TableLayout="Fixed">  
                <Columns> 
                    <telerik:GridButtonColumn CommandName="Select" Text="Details" UniqueName="colSelect" /> 
                    <telerik:GridHyperLinkColumn DataNavigateUrlFormatString="newwo.aspx?fac={0}&amp;cn={1}"   
                        DataNavigateUrlFields="FacilityID,ControlNum" Text="Open WO" UniqueName="OpenWO" ItemStyle-ForeColor="White" /> 
                    <telerik:GridBoundColumn DataField="ControlNum" HeaderText="SCTM Tag #" UniqueName="ControlNum" /> 
                    <telerik:GridBoundColumn DataField="CustTag" HeaderText="Facility Tag #" UniqueName="CustTag" /> 
                    <telerik:GridBoundColumn DataField="PriorTag" HeaderText="Prior Tag #" UniqueName="PriorTag" /> 
                    <telerik:GridBoundColumn DataField="Serial" HeaderText="Serial #" UniqueName="Serial" /> 
                    <telerik:GridBoundColumn DataField="ShortName" HeaderText="Facility" UniqueName="ShortName" /> 
                    <telerik:GridBoundColumn DataField="DeptName" HeaderText="Cost Ctr/Dept" UniqueName="DeptName" /> 
                    <telerik:GridBoundColumn DataField="EquipStatusName" HeaderText="Status" UniqueName="EquipStatusName" /> 
                    <telerik:GridBoundColumn DataField="ManfName" HeaderText="Manufacturer" UniqueName="ManfName" /> 
                    <telerik:GridBoundColumn DataField="DeviceDescription" HeaderText="Description" UniqueName="DeviceDescription" /> 
                </Columns> 
                <EditFormSettings> 
                    <EditColumn InsertImageUrl="Update.gif" UpdateImageUrl="Update.gif" EditImageUrl="Edit.gif" CancelImageUrl="Cancel.gif"></EditColumn> 
                </EditFormSettings> 
            </MasterTableView> 
            <ClientSettings> 
                <Scrolling ScrollHeight="100px" AllowScroll="true" UseStaticHeaders="true" FrozenColumnsCount="4" /> 
            </ClientSettings> 
            <FilterMenu EnableEmbeddedSkins="True"></FilterMenu> 
        </telerik:RadGrid> 

Any ideas?  Thanks in advance!

5 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 16 Apr 2009, 04:40 AM
Hello Steve,

You can access the hyperlink and then try setting its fore color as shown below:
c#:
 protected void gridResults_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
           if (e.Item is GridDataItem) 
            { 
                GridDataItem dataItem = (GridDataItem)e.Item;                                               
                HyperLink hyplink = (HyperLink)dataItem["OpenWO"].Controls[0]; 
                hyplink.ForeColor = System.Drawing.Color.White; 
                        
            } 
     } 

Thanks
Princy.
0
Steve LaForge
Top achievements
Rank 1
answered on 16 Apr 2009, 06:31 PM
Many thanks!  This works perfectly.  I do think this should have worked without this code but I'll take the workaround and move forward.
0
Nicolaï
Top achievements
Rank 2
answered on 26 Jun 2009, 06:35 AM
I'm sure it works, but we do have a itemstyle forecolor property that should work?
Also, css for anchors says blue, but it's still default black and ignores my css class that says A {color:blue;..}...
(and it does get rendered as an anchor)
Maybe Telerik should consider including this in the next update? I mean, links should be blue by default?
0
Dimo
Telerik team
answered on 26 Jun 2009, 08:40 AM
Hi Nicolai,

The ItemStyle properties (including ForeColor) are applied to table cells or table rows (depending on whether you are setting them per column or not). However, HTML anchors do not inherit color styles from parent elements (this is the way CSS works), so in either case the ForeColor setting does not work for hyperlinks.

You have to define color for hyperlinks directly with an appropriate CSS selector. In the case of RadGrid, you have to supply a CSS selector with a high-enough specificity, so that it overrides the default hyperlink color defined in the RadGrid skins.

http://blogs.telerik.com/dimodimov/posts/08-06-17/how_to_override_styles_in_a_radcontrol_for_asp_net_ajax_embedded_skin.aspx

Currently, the specificity of the hyperlink color styles in the RadGrid skins is 21, so this will override them:

.RadGrid_SkinName  .rgMasterTable  td  a   /* specificity 22 */
{
       color: ....... ;
}


Greetings,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Nicolaï
Top achievements
Rank 2
answered on 26 Jun 2009, 09:13 AM
Perfect..! Thanks.!
Tags
Grid
Asked by
Steve LaForge
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Steve LaForge
Top achievements
Rank 1
Nicolaï
Top achievements
Rank 2
Dimo
Telerik team
Share this question
or