ASP.net Insert blank rows into Gridview

给你一囗甜甜゛ 提交于 2019-12-12 01:13:14

问题


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?


回答1:


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();

You can see this




回答2:


For meeting your requirement , I think you shouldn't use sqldatasource to bind gridview instead of manual binding the datasource to gridview. you can encapsulate a datatable or dataview which each page have 10 rows as the datasource.



来源:https://stackoverflow.com/questions/8556692/asp-net-insert-blank-rows-into-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!