3

Can i in GridView add css to only first(headr) tr. I know how to add css to th inside header trr but i don't know if is possible to add css to trr?

GRIDVIEW:

<asp:GridView ID="gwCompanies" runat="server" AutoGenerateColumns="false">
        <Columns>            
            <asp:TemplateField HeaderText="Ime">               
                <ItemTemplate>
                    <asp:Image ID="imgServiceOpen" runat="server" ToolTip="Restavracija sprejema naročila" ImageUrl="~/Images/cheff-icon.png" Visible='<%# Convert.ToBoolean(Eval("ServiceOpen")) %>' />
                    <asp:HyperLink ID="hlEdit" runat="server" NavigateUrl='<%# GetOrderArticlesUrl(Eval("CompanyId")) %>'>
                        <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                    </asp:HyperLink>
                </ItemTemplate>                
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Naslov">
                <ItemTemplate>
                    <asp:Label ID="lblFullAddress" runat="server" Text='<%# GetFullCompanyAddress(Container.DataItem) %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <EmptyDataTemplate>
            <asp:Label ID="lblEmptyCompaniesGrid" runat="server" Text="Ne najdem restavracij!"></asp:Label>
        </EmptyDataTemplate>
    </asp:GridView>

output i want

<table id="rest_list">

  <tr class="top_tab">
    <td class="top_tab_title">Ime</td>
    <td class="top_tab_title">Naslov</td>
  </tr>

  <tr>
    <td class="rest_name"><a href="#" title="Murka">Murka</a></td>
    <td>Točen naslov pizzerije</td>
  </tr>

  <tr>
    <td class="rest_name"><a href="#" title="Lastoria">Lastoria</a></td>
    <td>Točen naslov pizzerije</td>
  </tr>

  <tr>
    <td class="rest_name"><a href="#" title="Skok">Skok</a></td>
    <td>Točen naslov pizzerije</td>
  </tr>

  <tr>
    <td class="rest_name"><a href="#" title="Tara">Tara</a></td>
    <td>Točen naslov pizzerije</td>
  </tr>

</table>
1
  • I'm curious as to why you asked another question, got an accepted answer/resolution and then deleted it? Commented Sep 5, 2010 at 12:37

2 Answers 2

4

You can add a class with the HeaderStyle property, like this:

<asp:GridView ID="gwCompanies" runat="server" AutoGenerateColumns="false">
  <HeaderStyle CssClass="top_tab" />

Or in the GridView tag, like this:

<asp:GridView ID="gwCompanies" runat="server" HeaderStyle-CssClass="top_tab" AutoGenerateColumns="false">
Sign up to request clarification or add additional context in comments.

Comments

1

Not sure I understand correctly, but you should use a HeaderTemplate to define your header row, e.g:

<asp:TemplateField HeaderText="Ime">               
  <ItemTemplate>
    ...
  </ItemTemplate>
  <HeaderTemplate>
    put here the content for the header row of this column
  </HeaderTemplate>
</asp:TemplateField>

Then you can apply whatever style you want to your header.

Comments

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.