gridview findcontrol返回空的“" [英] gridview findcontrol returning empty ""

查看:68
本文介绍了gridview findcontrol返回空的“"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过使用此代码从gridview内的文本框中读取内容

i am trying to read from a textbox within a gridview by using this code

    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            string textBoxText = ((TextBox)row.FindControl("numTC")).Text;
            Response.Write(textBoxText);

        }
    }

此代码不断返回"(空)

this code keeps returning "" (empty)

知道为什么会发生这种情况吗?

any idea why this is hapenning?

谢谢

推荐答案

请确保您未在​​页面的PostBack上重新绑定GridView.这可能是问题所在.

Make sure that you are not re-binding the GridView on the PostBack of the page. This may be the issue.

编辑

确保用于绑定GridView的代码在以下代码内:

Make sure that the code for Binding the GridView is within the code below:

C#

if ( !Page.IsPostBack ){
    // Code to bind the control
}

VB

If Not Page.IsPostBack Then
    ' Code to bind the control
End If

否则,将发生重建"控件的情况,并且所有值都将丢失在TextBox的

Otherwise what happens is that the controls is "rebuilt" and the values are all lost within the TextBox's

这篇关于gridview findcontrol返回空的“"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆