Solved

Gridview Header Image

Posted on 2012-03-30
5
536 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…

830 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