user1776979
user1776979

Reputation: 41

ASP.NET Grid View row with style never defined

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!

Upvotes: 3

Views: 2333

Answers (2)

Lareau
Lareau

Reputation: 2011

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).

Upvotes: 1

ORION
ORION

Reputation: 2411

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>

Upvotes: 0

Related Questions