3

I have a strange problem. I created a GridView that is bounded to an ObjectDataSource.

The strange thing I have now, that all Grid Rows have the style "background-color: White". But I never declared this and I can't find any place in my project where it is designed. Neither inline the .aspx nor any css or in any code behind. Simply this style definition doesn't exist in my project.

The information I add to the GridView directly are overwritten by the style definition. Here's what Firebug gets:

<div>
<table id="MainContent_UserGrid" cellspacing="0" cellpadding="4" style="width:100%;border-collapse:collapse;">
<tbody>
<tr style="color:White;background-color:#5D7B9D;font-weight:bold;">
<tr style="color:#333333;background-color:White;">
<td>
<td>[email protected]</td>
<td>Name of me</td>
<td>Y</td>
<td>
</tr>
<tr style="color:#284775;background-color:White;">
<tr style="color:#333333;background-color:White;">
<tr style="color:#284775;background-color:White;">
<tr style="color:#333333;background-color:White;">
</tbody>
</table>
</div>

Here's my ASPX code of the Grid:

<asp:GridView ID="UserGrid"
              runat="server"
              AutoGenerateColumns="False" 
              DataKeyNames="AD_ID"
              DataSourceID="UserByAdminAdapter" CellPadding="4" 
              GridLines="None" Width="100%" AllowPaging="True">

    <Columns>
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
            ShowSelectButton="True" />
        <asp:BoundField DataField="AD_ID" HeaderText="AD_ID" ReadOnly="True" 
            SortExpression="AD_ID"></asp:BoundField>
        <asp:BoundField DataField="NAME" HeaderText="NAME" SortExpression="NAME" 
            ReadOnly="True">
        </asp:BoundField>
        <asp:BoundField DataField="ACCOUNT_TYPE" HeaderText="ACCOUNT_TYPE" 
            SortExpression="ACCOUNT_TYPE" Visible="False" ReadOnly="True"></asp:BoundField>
        <asp:BoundField DataField="ADMIN_ID" HeaderText="ADMIN_ID" 
            SortExpression="ADMIN_ID" Visible="False" ReadOnly="True"></asp:BoundField>
        <asp:BoundField DataField="BOOKINGS_CONSISTENT" HeaderText="BOOKINGS_CONSISTENT" 
            SortExpression="BOOKINGS_CONSISTENT" ReadOnly="True"></asp:BoundField>
        <asp:BoundField DataField="COMPANY" HeaderText="COMPANY" 
            SortExpression="COMPANY" Visible="False" />
        <asp:TemplateField HeaderText="COMPANY_NAME" SortExpression="COMPANY_NAME">
            <EditItemTemplate>
                <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="Companies" 
                    DataTextField="NAME" DataValueField="ROW_ID" 
                    SelectedValue='<%# Bind("COMPANY") %>'>
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("COMPANY_NAME") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>

    <RowStyle  BackColor="#000000" ForeColor="#333333"  />
    <AlternatingRowStyle  BackColor="#99FFCC" ForeColor="#284775" />

    <EditRowStyle BackColor="#999999" />
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    <sortedascendingcellstyle backcolor="#E9E7E2" />
    <sortedascendingheaderstyle backcolor="#506C8C" />
    <sorteddescendingcellstyle backcolor="#FFFDF8" />
    <sorteddescendingheaderstyle backcolor="#6F8DAE" />

</asp:GridView>

By the way, changing the background color of a row in the c# code doesn't change anything, also. I have a workaround through css but that's not "nice".

Thank you right now!

2
  • anywhere in your CSS do you define styles for table, tr, or td? Commented Oct 26, 2012 at 12:09
  • 1
    Are there any .net themes in your project? Commented Oct 26, 2012 at 12:11

2 Answers 2

1

Do you have a theme somewhere in your project that could be overwriting your grid styles?

Could you be modifying the style somewhere in your code behind (I doubt it).

Instead of putting specific styles in your gridview footerStyle, why not make a class in your css and link to that so

<RowStyle  BackColor="#000000" ForeColor="#333333"  />

becomes

<RowStyle CssClass="ItemStyle" />

It might make it easier to trouble shoot in Firebug and reduce the amount of inline styles (and be more maintainable at the same time).

Sign up to request clarification or add additional context in comments.

3 Comments

What kind of theme do you mean? I tried to overwrite the bad style with a new GridView Theme but the bad styles didn't got overwritten.
I'm referring to the the asp.net themes & skins - msdn.microsoft.com/en-us/library/ykzx33wh%28v=vs.100%29.aspx
Mhh I defined a theme for GridViews for adding an DrowDown element in it. I will try to solve this that way... But I can definitly say that its not in the code behind.
0

It's auto styling. You can creat CSS Classes for your GridView and apply them to the following attributes:

        <HeaderStyle CssClass="tableHead"  />
        <RowStyle CssClass="tableRow" />
        <PagerStyle CssClass="pager" />

    //Example 
    <asp:GridView runat="server" ID="grdAssetSearchResults" AutoGenerateColumns="false" GridLines="Both" AllowSorting="true"  UseAccessibleHeader="true" >
        <HeaderStyle CssClass="tableHead"  />
        <RowStyle CssClass="tableRow" />
        <PagerStyle CssClass="pager" />
        <Columns>
         //Columns
        </Columns>
    </asp:GridView>

1 Comment

But why does AutoStyling add "background-color: White" ??? If I could I would stay with the ASPX way of styling the GridView instead of using css.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.