【问题标题】:How to add new rows to a DataTable which is bound to a gridview in the RowDataBound event?如何在 RowDataBound 事件中向绑定到 gridview 的 DataTable 添加新行?
【发布时间】:2014-05-21 14:29:23
【问题描述】:

我有一个关于向绑定到 RowDataBound 事件中的网格视图的数据表添加新行的问题。你知道我该怎么做吗?

【问题讨论】:

  • 您为什么要这样做? RowDataBound 会针对绑定到DataTable(我猜)的网格中的每一 行触发。所以你想在GridView已经数据绑定之后更改它的数据源?

标签: asp.net gridview datatable rowdatabound


【解决方案1】:

我会在 gridview 上使用 OnDataBound 事件。这样,在您的 rowdatabound 完成并且您的网格是数据绑定之后,将引发此事件。

<asp:gridview id="Gridview1" runat="server" ondatabound="Gridview_DataBound" 
...
</asp:gridview>

private void GridView_DataBound(EventArgs e)
{

if(e.Row.RowType == DataControlRowType.DataRow)
{
  //add row to here

}
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-12
    • 2018-08-13
    • 1970-01-01
    • 2011-05-24
    • 2014-08-30
    • 1970-01-01
    • 2010-10-30
    相关资源
    最近更新 更多