Make links different color in the datagrid

Discussion in 'ASP .Net Datagrid Control' started by Mike Chamberlain, Mar 14, 2005.

  1. 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
     
    Mike Chamberlain, Mar 14, 2005
    #1
    1. Advertising

  2. Mike Chamberlain wrote:
    > 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
     
    Mike Chamberlain, Mar 14, 2005
    #2
    1. Advertising

  3. Mike Chamberlain

    Riki Guest

    Mike Chamberlain wrote:
    > 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
     
    Riki, Mar 14, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. moondaddy
    Replies:
    3
    Views:
    38,960
    moondaddy
    Apr 28, 2004
  2. Terry Olsen

    Can I make links in a datagrid?

    Terry Olsen, Apr 8, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    546
    Brock Allen
    Apr 9, 2005
  3. rockdale
    Replies:
    1
    Views:
    2,451
    rockdale
    Jun 2, 2006
  4. Kamaljeet Saini
    Replies:
    0
    Views:
    486
    Kamaljeet Saini
    Feb 13, 2009
  5. Replies:
    1
    Views:
    309
    marss
    Feb 14, 2007
Loading...

Share This Page