Proper way to Display a empty row in a gridview
Posted on 2006-06-16
I am using gridviews in my application and they have bound columns and the datasource is a objectdatasource. When no records are returned I would like the gridview to display an empty row (with column headers etc.). From what I can tell the only way to accomplish this, without using an image within a EmptyDataTemplate or the worthless EmptyDataText property, is to create an arraylist and toss an empty oject into it and use that for the datasource. After the grid is bound I then have to blank out some cells because they have some default text in them (dates, boolens etc..). Then I get my empty row.
Is there an easier way to accomplish what I am looking for? Or I am I stuck just doing it like this? The reason why I would like to change it is because there is no way to force the objectdatasource to give me a record count (that I can find anyway) before it is bound. So I have to bind the objectdatasource to the grid then check the grid's Row.Count property and then if it is zero bind it again to my empty arraylist. Kinda wasteful.