Asp.net 如何从DataGridView获取文本框值?

Asp.net 如何从DataGridView获取文本框值?,asp.net,vb.net,Asp.net,Vb.net,所以在这里,我试图用DataGridView中选择的数据填充文本框,所以当我单击DataGridView中的按钮时,选择的结果将被放入文本框,我尝试了其他资源中的解决方案,但仍然没有成功。有人能帮忙吗?以下是DataGridView代码: DataGridView: <asp:Panel ID="PanelDGV" runat="server" ScrollBars="None" Height="250" Width="515"> <asp:GridView ID="

所以在这里,我试图用DataGridView中选择的数据填充文本框,所以当我单击DataGridView中的按钮时,选择的结果将被放入文本框,我尝试了其他资源中的解决方案,但仍然没有成功。有人能帮忙吗?以下是DataGridView代码:

DataGridView:

<asp:Panel ID="PanelDGV" runat="server" ScrollBars="None" Height="250" Width="515">
     <asp:GridView ID="DGV" runat="server" AutoGenerateColumns="False" GridLines="None" AllowPaging="true" PageSize="8" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
              <Columns>
     <asp:BoundField DataField="ProjectCode" HeaderText="Project Code" />
     <asp:BoundField DataField="ProjectName" HeaderText="Project Name" />
     <asp:ButtonField ButtonType="Image" ImageUrl="../Support/Image/Edit.png" ItemStyle-HorizontalAlign="Center" CommandName="CmdSearch" HeaderText="Edit">
              <ItemStyle HorizontalAlign="Center"></ItemStyle>
                    </asp:ButtonField>
              </Columns>
                    <PagerStyle CssClass="pgr"></PagerStyle>
                    AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
      </asp:GridView>
</asp:Panel>

AlternatingRowStyle CssClass=“alt”>
请注意,按钮是:

 <asp:ButtonField ButtonType="Image" ImageUrl="../Support/Image/Edit.png" ItemStyle-HorizontalAlign="Center" CommandName="CmdSearch" HeaderText="Edit">

哦,文本框的ID是“TbProjectCode”,两者都在单独的页面中,比如1.aspx包含文本框和打开datagridview的按钮,2.aspx包含datagridview和选择项目代码的按钮


谢谢

在网格上添加OnRowCommand事件查看:OnRowCommand=“DGV_OnRowCommand”

然后将此添加到代码后面:

    protected void DGV_OnRowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "CmdSearch")
        {
            int index = (int)e.CommandArgument;
            GridViewRow row = DGV.Rows[index];
            // Get the text on first cell of the row which is the project code.
            TbProjectCode.Text = row.Cells[0].Text;
        }
    }

下面是一些文档,它几乎告诉您如何做。(看下面的例子)这有点帮助,但是DataGrid和Textbox位于不同的页面上,有什么建议吗?文本框完全位于不同的页面上?是的,假设DataGrid位于data.aspx中,当我单击Textbox旁边的按钮(比方说是Textbox.aspx)时,它会弹出,当我单击DataGrid上的按钮时,datagrid将关闭,值将放在上一页文本框中我希望项目代码结果显示在文本框中,顺便说一句,我使用VB:),而且datagrid和文本框位于不同的页面谢谢你的回答,只有datagrid和文本框位于同一页面时,它才能正常工作,但是在我的例子中,DataGrid和Textbox所在的页面是不同的,有什么建议吗?嗯。。你能告诉我你用什么弹出窗口或者你是怎么做的吗?