Home All Groups Group Topic Archive Search About

Make links different color in the datagrid

Author
14 Mar 2005 5:35 AM
Mike Chamberlain
Hi.

I'm using the standard datagrid control in my ASP.NET page.  I have the
latest version and all service packs of the framework installed.  I am
using the property builder to create my grid.  My question is simple:
How do I make the links in different cells adopt a specific CSS class?

For instance, my header row in set to maroon and my links set to white.
  This makes the sortable columns headings display nicely (white on
maroon background).  But if I try to use a link somewhere else in my
grid (ie. a Hyperlink column) then it also appears as white on a WHITE
background.

How do I make the links in the header row use CSS class .linkHeader, but
make the links in the hyperlink column use .linkStandard?  I tried the
following but obviously it doesn't work:

<asp:HyperLinkColumn Text="..." DataNavigateUrlField="master_id_account"
DataNavigateUrlFormatString="Edit.aspx?masterIdAccount={0}"
CssClass="linkStandard"></asp:HyperLinkColumn>

['System.Web.UI.WebControls.HyperLinkColumn' does not have a property
named 'CssClass'.]

Mike

Author
14 Mar 2005 5:56 AM
Mike Chamberlain
Mike Chamberlain wrote:
Show quoteHide quote
> Hi.
>
> I'm using the standard datagrid control in my ASP.NET page.  I have the
> latest version and all service packs of the framework installed.  I am
> using the property builder to create my grid.  My question is simple:
> How do I make the links in different cells adopt a specific CSS class?
>
> For instance, my header row in set to maroon and my links set to white.
>  This makes the sortable columns headings display nicely (white on
> maroon background).  But if I try to use a link somewhere else in my
> grid (ie. a Hyperlink column) then it also appears as white on a WHITE
> background.
>
> How do I make the links in the header row use CSS class .linkHeader, but
> make the links in the hyperlink column use .linkStandard?  I tried the
> following but obviously it doesn't work:
>
> <asp:HyperLinkColumn Text="..." DataNavigateUrlField="master_id_account"
> DataNavigateUrlFormatString="Edit.aspx?masterIdAccount={0}"
> CssClass="linkStandard"></asp:HyperLinkColumn>
>
> ['System.Web.UI.WebControls.HyperLinkColumn' does not have a property
> named 'CssClass'.]
>
> Mike

I found a partial workaround myself.  First set the UseAccessibleHeader
property of the grid to True, which tells it to render the table
properly (using <TH> tags for the header cells rather than <TD> - why
this isn't the default is beyond me).  Then, two styles can be defined

TH A { color:white; }
TD A { color:maroon; }

which works fine for now.  But what happens if I want to have a link of
one color in one Hyperlink column, and one of a different color in another?

Any suggestions appreciated.

Mike
Author
14 Mar 2005 8:31 AM
Riki
Mike Chamberlain wrote:
Show quoteHide quote
> Hi.
>
> I'm using the standard datagrid control in my ASP.NET page.  I have
> the latest version and all service packs of the framework installed. I am
> using the property builder to create my grid.  My question is
> simple: How do I make the links in different cells adopt a specific
> CSS class?
> For instance, my header row in set to maroon and my links set to
>  white. This makes the sortable columns headings display nicely
> (white on maroon background).  But if I try to use a link somewhere
> else in my grid (ie. a Hyperlink column) then it also appears as
> white on a WHITE background.
>
> How do I make the links in the header row use CSS class .linkHeader,
> but make the links in the hyperlink column use .linkStandard?  I
> tried the following but obviously it doesn't work:
>
> <asp:HyperLinkColumn Text="..."
> DataNavigateUrlField="master_id_account"
> DataNavigateUrlFormatString="Edit.aspx?masterIdAccount={0}"
> CssClass="linkStandard"></asp:HyperLinkColumn>
> ['System.Web.UI.WebControls.HyperLinkColumn' does not have a property
> named 'CssClass'.]
>
> Mike

If the other columns don't contain links, you can set the CssClass property
of the ItemStyle and AlternatingItemStyle.

--

Riki