If the DataGrid uses paging, the last page may not be "full page", so there may be problems with the DataGrid's layout. The remaining rows will be too wide, and the entire DataGrid will become ugly.
Solutions can probably be considered from three places:
1. Fill in the new data rows in the DataSource.
2. Fill in the new blank control row in the DataGrid.
3. Use javascript to fill in the new html control row in the webpage.
I used the second method. In the response method of the datagrid's prerender event, fill in the blank line above the footer line. The code is as follows:
protected virtual void SpiderSurfGrid_PreRender(object sender, System.EventArgs e)
{
DataGridItem dgi;
System.Web.UI.WebControls.TableCell tablecell;
System.Web.UI.WebControls.TableRow tablerow;
DataGrid grid = (sender as DataGrid);
if(grid.Controls.Count == 0) return;
System.Web.UI.WebControls.Table table = (grid.Controls[0] as System.Web.UI.WebControls.Table);
tablerow = (System.Web.UI.WebControls.TableRow)(table.Controls[1]);
for(int j=this.PageSize+4-table.Controls.Count;j>0;j--)
{
dgi = new DataGridItem(0,0,ListItemType.Item);
for(int i=0;i<tablerow.Controls.Count;i++)
{
tablecell = new System.Web.UI.WebControls.TableCell();
dgi.Cells.Add(tablecell);
}
table.Controls.AddAt(table.Controls.Count-2,dgi);
}
}
Explanation: What is considered here is a bound datagrid with header/footer/pager rows and pager below.
What is strange is that I cannot add cssstyle to a line here. Once I dgi.cssstyle="dumpTableRowClass"; these newly added lines will collapse. If you have success, please give me some advice. Thank you.
Original by athossmth, please indicate when reprinting.