如何在gridview footer加多行
展开全部
// 自动填充的行数
int numCount = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GridView1.DataSource = CreateDataSourceByXianhuiMeng();
GridView1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// 计算自动填充的行数
numCount++;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
// 计算完毕,在此添加缺少的行
int toLeft = TotalRowCount - numCount;
int numCols = GridView1.Rows[0].Cells.Count;
for (int i = 0; i < toLeft; i++)
{
GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
for (int j = 0; j < numCols; j++)
{
TableCell cell = new TableCell();
cell.Text = " ";
row.Cells.Add(cell);
}
GridView1.Controls[0].Controls.AddAt(numCount + 1 + i, row);
}
}
}
int numCount = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GridView1.DataSource = CreateDataSourceByXianhuiMeng();
GridView1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// 计算自动填充的行数
numCount++;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
// 计算完毕,在此添加缺少的行
int toLeft = TotalRowCount - numCount;
int numCols = GridView1.Rows[0].Cells.Count;
for (int i = 0; i < toLeft; i++)
{
GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
for (int j = 0; j < numCols; j++)
{
TableCell cell = new TableCell();
cell.Text = " ";
row.Cells.Add(cell);
}
GridView1.Controls[0].Controls.AddAt(numCount + 1 + i, row);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询