views:

458

answers:

3

I'm just starting to use the ASP.NET GridView control.

i was thinking of adding an "Add New Row" button to the Footer to add a new data row to the grid.

Initially, I want the grid to be empty, with only a footer row displayed. however, if there are no data rows, the whole grid doesn't appear and there is no way to add first row since the footer also is not shown.

Is there a way to display a grid with only a footer and no data rows or do I have to resort to a kludge?

+1  A: 

The ASP.NET DataGrid will not show anything (or optionally show just a 'No Data Text value if you specify), if it does not have any rows. We wanted to show at least the grid header, even if no data or rows existed. One trick we have done in the past, is to add an empty row to the grid. This will cause the header / footer to appear. In the case of the header, we positioned a div over the empty row with some nicely formated text...just to pretty it up.

PortageMonkey
+1 Yeah, I was thinking of this, but I consider it a kludge. I'm surprised that the grid doesn't support it. Still looking...
Velika
+1  A: 

Have you looked into subclassing the GridView and overriding its CreateChildControls method (and possibly some render methods as well if required)?

You may be able to alter its default behaviour. If this is possible, it would be less kludgy than adding empty rows.

Quick Joe Smith
Good suggestion. But it must have been done before, preferablly in VB.NET, so I can learn and modify as needed.
Velika
If it's been done before, Google will surely have something. Failing that, you always have IntelliSense and Redgate Reflector if necessary.
Quick Joe Smith
A: 

I dont know if this would work. But we had a similar issue with Telerik RadGrid-> The grid does not display if datasource = null. For some reason though it had a "no records template" it did not work. setting datasource = new object[]{} did the trick, it showed an empty grid. my 2 cents

ram