Solved

Gridview Header Image

Posted on 2012-03-30
5
531 Views
Last Modified: 2012-03-31
I'm trying to display a background image in my gridview header. This is what I have so far but it won't display the image. Any help is appreciated.


<asp:GridView ID="Users" runat="server" AutoGenerateColumns="False" CssClass="myheader"
                PageSize="20" AllowPaging="True" ondatabound="Users_DataBound" BackColor="Transparent"
                onpageindexchanging="Users_PageIndexChanging">                
                <Columns>
                    <asp:BoundField HeaderText="Emp_Id" DataField="Emp_Id" />
                    <asp:BoundField HeaderText="Last Name" DataField="Last_Name" 
                        ItemStyle-HorizontalAlign="Left" >
                    </asp:BoundField>
                    <asp:BoundField DataField="First_Name" HeaderText="First Name" 
                        ItemStyle-HorizontalAlign="Left" >
                    </asp:BoundField>
                </Columns>
                <HeaderStyle BorderStyle="None" />
            </asp:GridView>

Open in new window

0
Comment
Question by:baxtalo
  • 2
  • 2
5 Comments
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 37789530
0
 
LVL 35

Assisted Solution

by:Miguel Oz
Miguel Oz earned 250 total points
ID: 37789540
Please disregard my first comment,
For header only, you need to use css.
Check:
http://bytes.com/topic/asp-net/answers/513572-background-image-gridview-header
0
 

Author Comment

by:baxtalo
ID: 37789609
I tried it with no success. Maybe I'm missing something. This is what I put in my css file:
..gvHeaderRow
{
background-image:url(../images/background_silver.jpg)
}
After that I added CssClass here:

<asp:GridView ID="Users" runat="server" AutoGenerateColumns="False"
PageSize="20" AllowPaging="True" ondatabound="Users_DataBound"
onpageindexchanging="Users_PageIndexChanging" CssClass="gvHeaderRow">
0
 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 250 total points
ID: 37789793
You have set CssClass for the whole gridview and not for header portion. So code as:

stylesheet code part: (ensure the url part in .css file in context to root and class name should be prefixed with single dot)
.gvHeaderRow
{
    background: url('Images/background_silver.jpg') repeat-x;
    color: #01354d;
    height: 25px;
    color: White;
}

Open in new window


.aspx code part (set headerstyle css class)
<asp:GridView ID="Users" runat="server" AutoGenerateColumns="False" CssClass="myheader"
                PageSize="20" AllowPaging="True" ondatabound="Users_DataBound" BackColor="Transparent"
                onpageindexchanging="Users_PageIndexChanging">                
                <Columns>
                    <asp:BoundField HeaderText="Emp_Id" DataField="Emp_Id" />
                    <asp:BoundField HeaderText="Last Name" DataField="Last_Name" 
                        ItemStyle-HorizontalAlign="Left" >
                    </asp:BoundField>
                    <asp:BoundField DataField="First_Name" HeaderText="First Name" 
                        ItemStyle-HorizontalAlign="Left" >
                    </asp:BoundField>
                </Columns>
                <HeaderStyle CssClass="gvHeaderRow" />
            </asp:GridView>

Open in new window

0
 

Author Closing Comment

by:baxtalo
ID: 37790982
Thank you very much; I've learned something from both of you.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question