【问题标题】:I need to copy the text from a gridview texbox to the others in the column我需要将文本从 gridview 文本框中复制到列中的其他文本
【发布时间】:2009-07-21 15:17:24
【问题描述】:

这是我的 C# 代码

protected void ibtCopiar_Click(object sender, ImageClickEventArgs e) {

           GridViewRow grdrows = DGPlanilla.Rows[0];
            TextBox tb1 = (TextBox)grdrows.FindControl("TextBox1");
            string valor = tb1.Text;

                if (valor != null || valor != "0")
                {
                    foreach (GridViewRow grdrow in DGPlanilla.Rows)
                    {
                        grdrow.Cells[5].Text = valor;
                    }
               }

    }

这是我的按钮代码

当我调试时,我看到我在第一个框中的值被传递到列中的其他文本框,但是当它破坏页面时,只有第一个框显示我输入的值。其他 texboxes 不会改变。

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    如果其他单元格也包含文本框,则需要找到它们并设置它们的文本值。

    foreach (GridViewRow grdrow in DGPlanilla.Rows)
    {
        TextBox toDisplay = (TextBox)grdrow.FindControl("TextBox1");
        toDisplay.Text = valor;
    }
    

    【讨论】:

    • 我确实尝试过 TextBox tb2 = (TextBox)grdrow.FindControl("TextBox1"); tb2.Text = string.Empty; tb2.Text = 勇气;我得到了同样的结果,只有第一个文本框的值
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 2010-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多