0

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
Gopal
  • 11,712
  • 52
  • 154
  • 229

3 Answers3

2

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.

Tim Coker
  • 6,484
  • 2
  • 31
  • 62
0

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

Community
  • 1
  • 1
Krunal
  • 3,443
  • 3
  • 23
  • 27
0

If it is populated manually, you can write string.Empty; for each row, if returned rowCount == 0

Serkan Hekimoglu
  • 4,234
  • 5
  • 40
  • 64