tags:

views:

106

answers:

3

Hi I am having a small issue. I am creating a SPGridView on the fly within a web part and adding it to the web part with some data in it. This works fine. I have now decided to rey make it look a little funky!!

However i cannot seem to get my cssclass property to work.

I have a class in the css file

.SPGridviewsCSS th
{
background-color:#e60004;
color: Blue!important;
background-image:none;
}

.SPGridviewsCSS td
{
 border-bottom-style: solid ;
 border-bottom-width: 1px ;
 border-bottom-color: #e60004 ;
}

and in my oninit event

CssRegistration.Register("/Styles/Style.css");

then

myspgridview.cssclass = "SPGridviewsCSS" 

all I want is it to make the grid view look good!!!

A: 

I am not a CSS expert, but th and td are not direct descendants of the table element of the grid, so maybe you should try:

.SPGridviewsCSS * td

Have a look here.

Timores
I've tried but still not working, but thanks for the reply. It's really funny as i have borrowed the css from a colleague(who has now left) and the way they have applied it is in the exact same way yet mine doesn't work and his does!!!!
Truezplaya
Have you tried with the developer tools of IE (or the equivalent of another browser) to see the classes and applied styles of the th and td in the "grid" ?
Timores
When you use the tools it shows that the info is all being rendered within a table and doesn't refer to a spgridview
Truezplaya
A: 

Using IE Developer Toolbar (or, may I suggest Firebug w/ Mozilla Firefox), can you verify what HTML output element the CSS class is being applied to?

I have a feeling that the primary CSS selector (.SPGridviewsCSS) is failing, and therefore nothing is being styled.

Also helpful might be posting a snippet of the HTML output so we can see what you're trying to style.

CBono
A: 

Hello!

I'm using some server code for SPGridView styling. It is not very elegant solution, but it works perfectly. If you don't have much time to find the better solution, you can use this code in your user control or aspx page, where the SPGridView control is placed:

protected override void CreateChildControls()
{
    // ...
    spGridView.RowStyle.CssClass = "spgridview-td";
    spGridView.AlternatingRowStyle.CssClass = "spgridview-td-alternating";
    this.Controls.Add(spGridView);
    // ...
}

Of course, you can use aspx markup instead of generating controls. For example:

<asp:SPGridView ID="spGridView" runat="server">
    <RowStyle CssClass="spgridview-td" />
    <AlternatingRowStyle CssClass="spgridview-td-alternating" />
</asp:SPGridView>

Next thing is attach styling to header:

protected override void Render(HtmlTextWriter writer)
{
    // ...
    spGridView.DataBind();
    if (spGridView.HeaderRow != null)
    foreach (TableCell cell in spGridView.HeaderRow.Cells)
        cell.CssClass = "spgridview-th";
    // ...
}

So, your css will be:

.spgridview-th
{
    background-color:#e60004;
    color: Blue!important;
    background-image:none;
}

.spgridview-td
{
    border-bottom-style: solid ;
    border-bottom-width: 1px ;
    border-bottom-color: #e60004 ;
}

.spgridview-td-alternating
{
}

Hope, this helps!

omlin
I have tried but to no avail :(. I am going to start a new project and see if i can get it working that way rather than trying to apply it to my situation.
Truezplaya