【问题标题】:TextBox not posting values in GridViewTextBox 不在 GridView 中发布值
【发布时间】:2021-07-29 21:02:27
【问题描述】:

我不知道为什么 TextBox 在这个 GridView 中是空的:

<asp:GridView ID="ContatosGrid" runat="server" AutoGenerateColumns="False">
        <Columns>
            <asp:BoundField DataField="NomeContatoOriginal" HeaderText="Contato Original" readonly="true" />
            <asp:TemplateField HeaderText="Contato Novo">
                    <ItemTemplate>
                        <asp:TextBox ID="txtNomeContatoNovo" runat="server" Text='<%# Bind("NomeContatoNovo") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
        </Columns>
    </asp:GridView>

在 TextBox 中用一些值填充第一行并点击保存按钮后:

protected void salvar_Click(object sender, EventArgs e)
    {
        var nomeContatoOriginal = ContatosGrid.Rows[0].Cells[0].Text; // ok, original value
        var nomeContatoNovo = ContatosGrid.Rows[0].Cells[1].Text; // always empty
    }

只有在 !PostBack 时才会调用网格的 DataBing。

【问题讨论】:

    标签: asp.net gridview webforms


    【解决方案1】:

    可以试试

    TextBox txtSNo = (TextBox)ContatosGrid.Rows[0].FindControl("txtNomeContatoNovo");
    
    string nomeContatoNovo = txtSNo.Text;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多