Sreenivas Mogullapalli

Microsoft Technologies Geek
posts - 44, comments - 40, trackbacks - 6

My Links

News



Archives

Post Categories

.NET Framework

SQL Server

showing gridview header row when no data

I have used gridviews in my asp.net 2.0 applications. One of the requirement is to show the header row even when there are no data rows in dataset. I couldn't find an easy way of doing this. After little bit of R&D, i did that with EmptyDataTemplate of GridView. This works well but is there any easy way of doing this?

EDIT on 15-Nov-2007:
Following is the sample code of what i did in my application. In this i wanted to show two fields Year and extract date. BTW, this sample is not specific to VB or C# as this code belongs to aspx page.

code:
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
                    Width="75%" BorderColor="Black" BorderStyle="Solid" OnRowDataBound="GridView1_RowDataBound" OnDataBound="GridView1_DataBound" AllowPaging="True">
                    <Columns>
                        <asp:BoundField DataField="YEAR" HeaderText="Year" >
                            <HeaderStyle Font-Underline="True" />
                        </asp:BoundField>
                        <asp:BoundField DataField="EXTRACT_DATE" HeaderText="Last Extract" >
                            <HeaderStyle Font-Underline="True" />
                        </asp:BoundField>
                    </Columns>
                    <EmptyDataTemplate>
                        <table width="100%">
                            <tr style="font-weight:bold; text-decoration:underline" align="center">
                                <td>
                                    Year
                                </td>
                                <td>
                                    Last Extract
                                </td>
                            </tr>                                                                                 
                        </table>                       
                         <br />
                        No Records Found for Review
                    </EmptyDataTemplate>
                </asp:GridView>

Print | posted on Friday, June 16, 2006 8:12 AM | Filed Under [ Microsoft ASP.NET ]

Feedback

Gravatar

# re: showing gridview header row when no data

How about adding a new row to the datatable you are binding, if no rows, then do the binding and then remove the first row in the gridview?
12/13/2006 12:25 PM | Siderite
Gravatar

# re: showing gridview header row when no data

can you provide an example in vb
1/23/2007 4:03 AM | kf
Gravatar

# re: showing gridview header row when no data

I need it
2/22/2007 11:38 PM | flaiz
Gravatar

# re: showing gridview header row when no data

please
you help me, code c#
11/13/2007 2:14 PM | fooladi
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: