【问题标题】:How can I be able to pass the data in the textbox into the gridview after clicking submit button(单击提交按钮后,如何将文本框中的数据传递到gridview(
【发布时间】:2017-06-22 07:04:23
【问题描述】:

当我单击提交按钮时,我无法在 gridview 中看到数据。我需要进行哪些更改才能在 GridView 中看到数据?

protected void Button1_Click(object sender, EventArgs e)
    {
           DataTable table = new DataTable();
           table.Columns.Add("ProductId");
           table.Columns.Add("ProductName");
           table.Columns.Add("ExpiryDate");
           table.Columns.Add("Price");
           table.Columns.Add("LotNumber");
           DataRow dr = table.NewRow();
           dr["ProductId"] = ProductId.Text;
           dr["ProductName"] = ProductName.Text;
           dr["ExpiryDate"] = ExpiryDate.Text;
           dr["Price"] = Price.Text;
           dr["LotNumber"] = LotNumber.Text;
           table.Rows.Add(dr);
           GridView2.DataSource = table;
           GridView2.DataBind();
    }

【问题讨论】:

  • 您的代码应该可以工作。有什么问题?
  • @MortalKombat 1. 发布您的标记(您的 aspx 或 ascx)。 2. 您是否收到错误消息?
  • 你检查过这段代码是否被执行了吗?意味着它是正确的事件处理程序。此外,您是否确认您正在更新正确的 GridView?看起来你有两个。
  • 是的,对不起,它起作用了。我更新了错误的 GridView。它应该是 GridView1 而不是 GridView2。谢谢@KernalMode。
  • 如果这个问题解决了就删除这个帖子

标签: c# asp.net gridview data-binding webforms


【解决方案1】:

根据代码,您有两个GridView。验证您更新了正确的。

【讨论】:

    猜你喜欢
    • 2021-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-02
    • 2012-01-24
    • 2021-08-26
    相关资源
    最近更新 更多