Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.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# 如何在GridView中从标签复制到文本框_C#_.net_Gridview - Fatal编程技术网

C# 如何在GridView中从标签复制到文本框

C# 如何在GridView中从标签复制到文本框,c#,.net,gridview,C#,.net,Gridview,在c.NETGridView中,当我尝试在Gridview中将一个值从Label单元格复制到TextBox单元格时,TextBox单元格变为Label 在_row命令中: 行。单元格[2]。文本在从文本框分配到标签后更改 有什么原因和解决办法吗 备注:我添加了代码以进行更多解释 .aspx代码: <asp:GridView ID="GridView_Names" runat="server" AutoGenerateColumns="False" Data

在c.NETGridView中,当我尝试在Gridview中将一个值从Label单元格复制到TextBox单元格时,TextBox单元格变为Label

在_row命令中:

行。单元格[2]。文本在从文本框分配到标签后更改

有什么原因和解决办法吗

备注:我添加了代码以进行更多解释

.aspx代码:

<asp:GridView ID="GridView_Names" runat="server" 
                AutoGenerateColumns="False" DataKeyNames="Num" 
                OnRowDataBound="GridView_Names_RowDataBound"
                OnRowCommand="GridView_Names_RowCommand"
                AllowPaging="false"  >
                <Columns>
                    <asp:BoundField DataField="Num" >
                    </asp:BoundField>
                    <asp:BoundField DataField="Name1" >
                    </asp:BoundField>
                    <asp:TemplateField >
                        <ItemTemplate >
                            <asp:TextBox ID="Name2" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField> 
                    <asp:TemplateField HeaderText="Google" Visible="false" >
                        <ItemTemplate>
                            <asp:Button ID="Button_Copy" 
                                CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" 
                                CommandName="OnClickButton_Copy" runat="server"/>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns></asp:GridView>

我必须使用以下命令TextBoxrow.FindControlName在Gridview中查找文本框:

protected void GridView_Names_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "OnClickButton_Copy")
{
    int index = Convert.ToInt32(e.CommandArgument);

    GridViewRow row = GridView_Names.Rows[index];
    //GridView_Names.Rows[index].Cells[2].Text = row.Cells[1].Text; // Cells[2] changes from TextBox to Label !!!
        TextBox txtName = (TextBox)row.FindControl("Name");
        txtName.Text= row.Cells[3].Text;

}

你能澄清发生了什么事吗?一步一步地了解正在发生的事情。谢谢。我刚刚添加了更多解释的代码。
    protected void GridView_Names_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
            e.Row.Cells[2].Text = e.Row.Cells[1].Text; // Cells[2] changes from TextBox to Label !!!
    }
}
protected void GridView_Names_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "OnClickButton_Copy")
    {
        int index = Convert.ToInt32(e.CommandArgument);

        GridViewRow row = GridView_Names.Rows[index];
        GridView_Names.Rows[index].Cells[2].Text = row.Cells[1].Text; // Cells[2] changes from TextBox to Label !!!
    }
protected void GridView_Names_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "OnClickButton_Copy")
{
    int index = Convert.ToInt32(e.CommandArgument);

    GridViewRow row = GridView_Names.Rows[index];
    //GridView_Names.Rows[index].Cells[2].Text = row.Cells[1].Text; // Cells[2] changes from TextBox to Label !!!
        TextBox txtName = (TextBox)row.FindControl("Name");
        txtName.Text= row.Cells[3].Text;

}