Solved

Gridview Header Image

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

15 Experts available now in Live!

Get 1:1 Help Now