【发布时间】:2014-03-18 06:25:58
【问题描述】:
我有 GridView,下面有一个 Button。单击按钮后,我想在 GridView 下方添加一个新的空白行
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnTest" Text="Test" runat="server" OnClick="btnTest_Click" />
</div>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<strong>Dynamic Grid</strong></td>
</tr>
<tr>
<td>
<asp:GridView ID="GrdDynamic" runat="server" AutoGenerateColumns="true"
OnRowDataBound="GrdDynamic_RowDataBound" >
</asp:GridView>
</td>
</tr>
</table>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</form>
</body>
</html>
并且数据正在通过以下方式填充......
在 pageLoad 中我正在调用绑定
DataTable dt = GroupBudgetSetUpBLL.Instance.GetAllGroupBudgetSetUp();
GrdDynamic.DataSource = dt;
GrdDynamic.DataBind();
在 rowdatabound 中,我正在制作 Grid Editable 文本框。
protected void GrdDynamic_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 1; i < e.Row.Cells.Count; i++)
{
TextBox txt = new TextBox();
string budget = e.Row.Cells[i].Text.Split('_').LastOrDefault();
string txtID = e.Row.Cells[i].Text.Split('_').FirstOrDefault() + "_" + e.Row.Cells[i].Text.Split('_').Skip(1).FirstOrDefault();
txt.ID = txtID;
txt.Text = budget;
e.Row.Cells[i].Text = "";
e.Row.Cells[i].Controls.Add(txt);
}
}
}
现在单击 Grid 下方的“按钮”后,我想在 MainGrid 下方显示一个空白行,单元格控件类型将为 TextBox 以便它保持可编辑状态。
【问题讨论】:
标签: c# asp.net gridview data-binding