Reputation: 12012
Using VS2005
In my webpage am using gridview, In a Gridview values is displaying from the table, if there is no value in the table gridview is displaying only the header, it should display a blank columns
I want to adjust the header font, content font....
Expected Output
Adjust the Header font, content font of the Gridview
Gridview should display the blank column if there is no data
Upvotes: 0
Views: 2045
Reputation: 6524
One option is to modify your SQL to always return a row. If you're executing an SP, you can do a select count(*)
from the table using your where clause, and if that's zero, do something like select '' col1, '' col2 ...
and return that.
Another option is to check the count of rows return in your code. If you're using a DataTable
or DataSet
, this is easy, as you can look at DataTable.Rows.Count
or DataSet.Tables[0].Rows.Count
respectively. If you have none, add a row to the table then bind it to your grid. If you're binding to a DataReader, you can look at the DataReader.HasRows
property.
Another option is to extend the DataGrid and add your own "No Rows Available" display mode.
The best option all all depends on your level of experience and the environment in which this code is running.
Upvotes: 2
Reputation: 4284
If it is populated manually, you can write string.Empty; for each row, if returned rowCount == 0
Upvotes: 0
Reputation: 3551
To show the gridview header you can add a blank row to the datatable/dataset and bind it with gridview.
This question is already answered here.
GridView - Show headers on empty data source
Upvotes: 0