views:

1726

answers:

2

Hello Friends,

I am using datatable to fill gridview.

How can i add blank row in datatable to view footertemplate even if i don't have any data ?

I am using asp.net 2005. I am using gridview control to add,edit and modify the data. i put add control at footertemplate. it's working fine but i face one problem that when ever there is no data in the grid then footertemplate is not visible. I want footertemplate will be visible all the time so that user can add data even though there is no data available.

Can any body help me out...

Thanks

+1  A: 

I ran into this as well. If I remember correctly, there is no way to actually fix it. I worked around the issue by creating an empty data template that had the controls I needed to be able to add the data.

Jeff Barger
+1  A: 

There are a couple tricks to doing this, and most of them are kind of "ad hoc". The route I took was to intercept my datasource and check the row count. If the row count was 0, then I went ahead and injected my own row into the dataset with a coded "blank" value. Then in the databinding event, I made sure that the empty row just put empty strings into the proper fields, allowing the footer to still render.

The other route to go would be to essentially subclass the GridView class and add a few extensions so that you can still display the header/footer when there is no data. Matt Berseth has a nice little article on how to accomplish this.

Dillie-O
i see that artical but how can i add that custom property in gridview
Kartik
What you're doing is creating your own class, call it KartikGridView that implements the GridViewClass so that you can extend it with the code provided. Then on your asp.net page, you'll use new tag instead of the GridView. Find the demo link in that article. It will have the source code to download
Dillie-O