【发布时间】:2015-04-08 14:07:57
【问题描述】:
如何在 asp 文本框中将文本框值分配给 gridview 是一个单独的对象,而不是 gridview 的一部分。在按钮单击事件上,所有文本框值都分配给网格视图作为新行。 我想知道如何做到这一点我搜索了很多但找不到正确的方法来做到这一点。 ![在此处输入图片说明][1]
DataTable dt = new DataTable();
DataRow dr = dt.NewRow();
if (e.CommandName.CompareTo("ADD") == 0)
{
dt.Columns.Add("id", System.Type.GetType("System.String"));
dt.Columns.Add("Name", System.Type.GetType("System.String"));
dt.Columns.Add("UnitPrice", System.Type.GetType("System.String"));
dt.Columns.Add("Price", System.Type.GetType("System.String"));
dt.Columns.Add("Quantity", System.Type.GetType("System.String"));
dr["Id"] = GridView1.Rows[Convert.ToInt16(e.CommandArgument)].Cells[0].Text;//item id
dr["Name"] = GridView1.Rows[Convert.ToInt16(e.CommandArgument)].Cells[1].Text;//item name
dr["UnitPrice"] = GridView1.Rows[Convert.ToInt16(e.CommandArgument)].Cells[2].Text;//iten unit price
dr["Price"] = "mkj";
dr["Quantity"] = "mkj";
dt.Rows.Add(dr);
GridView2.DataSource = dt;
GridView2.DataBind();
}
【问题讨论】: