Hi!
Is it possible to force the grid to generate columns even though the table has 0 rows? I dropped a grid on an aspx page in the designer and after binding a dataset which has a table with 0 rows, the columsn do get generated (so the user can see that the report did run but dodn't generate any data). Note: I have AutoGenerateColummns = true (in the designer).
Then, as a test, on another page, I create a grid programmatically, using:
UltraWebGrid grid = new UltraWebGrid("UltraWebGrid1");
and set AutoGenerateCOlumns to true.
However, after:
grid.DataSource = ds.Tables[0];
grid.DataBind();
I get "Object not set (NullReference)" exception.
So, the question is: how is it that when created in the designer the grid does generate columns gracefully, but when created dynamically, the grid throws an exception on DataBind() ?
Thanks in advance!
Regards,
S
Thanks for the reply.
Well, my grid is supposed to show data to the user without "Add New" row (the user is not supposed to edit the data).
I think what's interesting about this case is that both grids are being populated using identical data sets (they both call the same stored proc with the same parameters). When examined in the debugger, you can see that the data set that's returned by the stored proc DOES contain 2 tables. You can even do column count on those tables to confirm that the tables exist and the columns are there. However, when you look at the Rows collection of the table in questions, the Count is 0. So, the grid that was created in the designer does generate the columns, but the dynamically-created grid doesn't (even though they both have AutoGenerateColums = true).
I think the discrepancy in behavior comes form the fact that when generated in the designer, the grid sets some defaults that I'm probably missing in my dynamically-created one. I just thought that AutoGenerateColumns would do the trick.
If you're trying to force the column headers/footers to render when there are no rows, I don't know of a way to do that. Maybe someone else does.
I could be wrong, but it sounds to me like you don't even have an empty table in ds.Tables[0].
But in either case, you might consider detecting the null/empty DataTable, and either A) Open the AddNew row, or B) generate a row full of empty (null, "") values.