【问题标题】:How to assign textbox value to gridview in asp textbox is a seperate object not a part of gridview如何在asp文本框中将文本框值分配给gridview是一个单独的对象,而不是gridview的一部分
【发布时间】: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();
        }

请看这张图片 http://i.stack.imgur.com/FkhZe.png

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    你可以试试这个

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-28
      • 1970-01-01
      • 1970-01-01
      • 2018-03-23
      • 1970-01-01
      相关资源
      最近更新 更多