Solved

Gridview Header Image

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now