I have a gridview that is bound to a sqldatasource. The Gridview only has a pagesize of 10 and I would like each page to have 10 rows. Therefore if only 5 data rows exist then I would like to add an additional 5 empty rows. Is this easy to do?
-
Why you want to add blank rows? Much better if you retain your binding as is..BizApps– BizApps2011-12-19 03:18:50 +00:00Commented Dec 19, 2011 at 3:18
-
I need all the pages to have 10 rowskarlstackoverflow– karlstackoverflow2011-12-19 03:27:27 +00:00Commented Dec 19, 2011 at 3:27
Add a comment
|
2 Answers
Fill your data into data set and count the number of rows retrieved then fill the remaining to the dataset with empty dataRows try this: Suppose you have a DataSet dt filled with the table or data you want
int remainingRows=10 - dt.Rows.Count;
DataRow dr;
for (int i = 0; i < remainingRows; i++)
{
dr = dt.NewRow();
dr[0] = dr[1] = dr[2] = dr[3] = dr[4] = "";//index goes the no of cols in the table
dt.Rows.Add(dr);
}
dt.AcceptChanges();
grdView.DataSource = dt;
grdView.DataBind();