如何在gridview footer加多行

如何在gridview footer加多行,第1张

// 自动填充的行数

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 = 0i <toLefti++)

{

GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal)

for (int j = 0j <numColsj++)

{

TableCell cell = new TableCell()

cell.Text = " "

row.Cells.Add(cell)

}

GridView1.Controls[0].Controls.AddAt(numCount + 1 + i, row)

}

}

}

你的GridView控件是用来显示你数据库里某些数据的。你另外自己添加一个Button控件。然后写个函数,添加GridView.DataSource的项,重新显示就能够自己增加一行,并且更新表的内容了!


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11545801.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存