Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在asp.net中将文本框输入传递到gridview?_C#_Asp.net_Gridview - Fatal编程技术网

C# 如何在asp.net中将文本框输入传递到gridview?

C# 如何在asp.net中将文本框输入传递到gridview?,c#,asp.net,gridview,C#,Asp.net,Gridview,我的网络表单中有两个文本框和一个gridview。gridview与数据库绑定。但我想在运行时上再添加一列,这将是来自webform的文本框输入。因为这个场景是这样的:我使用两个文本框维护两个公式来计算某个百分比,客户端希望看到gridview中每一行的计算结果 但我不能这样做 有人能帮我吗?也许有一些建议 提前谢谢 您可以使用label控件在GridView标记中添加列以显示结果,如下所示 这是所需的标记,请注意Visible设置为false <asp:GridView ID="Grid

我的网络表单中有两个文本框和一个gridview。gridview与数据库绑定。但我想在运行时上再添加一列,这将是来自webform的文本框输入。因为这个场景是这样的:我使用两个文本框维护两个公式来计算某个百分比,客户端希望看到gridview中每一行的计算结果

但我不能这样做

有人能帮我吗?也许有一些建议


提前谢谢

您可以使用label控件在GridView标记中添加列以显示结果,如下所示

这是所需的标记,请注意Visible设置为false

<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField Visible="false">
    <ItemTemplate>
        <asp:Label ID="label1" runat="server"></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

请原谅任何错误,我没有测试上述内容。

当然,兄弟。我很乐意这样做:)
void GridView1GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{ 
 if(e.Row.RowType == DataControlRowType.DataRow)
 {
  //find the control
  var label1 = e.Item.FindControl("label1") as Label;
  if (label1 != null)
  {
   if (!string.IsNullOrEmpty(tbInput1.Text) && !string.IsNullOrEmpty(tbInput2.Text))
   {
      // Do the calculation and set the label
      label1.Text = tbInput1.Text + tbInput2.Text;
      // Make the column visible
      GridView1.Columns[0].Visible = true;
   }
  }
 }
}