如何在asp中为网格视图分配文本框值文本框是一个单独的对象,而不是网格视图的一部分



如何在asp中为gridview分配textbox值textbox是一个单独的对象,而不是gridview的一部分。按钮单击事件所有文本框值分配给网格视图作为neew行。我想知道如何做到这一点,我搜索了很多,但找不到正确的方法。![在此输入图像描述][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();
        }

请看这个imghttps://i.stack.imgur.com/FkhZe.png

你可以试试这个

Gridview.Rows[1].Cells[0].Text = TextBox1.Text;

最新更新