本文介绍了Gridview文本框在'findcontrol'上返回NULL值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,文本框模板字段在代码后面动态添加,输入值到文本框。在获取文本框值时,它返回空。



以下代码我试图获得价值。



'***我输入你好值在执行下面的代码之前在文本框控件中。



i have a gridview with text box template field added dynamically in code behind, entered value to text box. While fetching the text box value, it's returning empty.

Below code i tried to get value.

'*** I entered "Hello" value in text box control before executing below code.

For Each row As GridViewRow In GridviewChild.Rows

            Dim tbSigningGroup As TextBox = DirectCast(row.Cells(4).FindControl("tbSigningGroup" + CStr(row.RowIndex)), TextBox)

            If Not tbSigningGroupIs Nothing Then
                Dim temp As String = tbSigningGroup.Text  ' ****** Returns NULL*******
            End If

Next





'****任何建议,我在哪里做错了?



我尝试过:



我使用CurrentRow.FindControl(ControlID)方法获取值,但仍然我得到空字符串作为返回值。



'****Any suggestions, where am i doing wrong?

What I have tried:

I used CurrentRow.FindControl("ControlID") method to get the value, but still i am getting empty string as return value.

推荐答案

 Dim Lbl_Control As Label= CType(row.FindControl("Label1"), Label)
// button click as usual, just get and check the value of Label control, rather than TextBox control.

Protected Sub B_Load_Click(ByVal sender As Object, ByVal e As EventArgs) '(sender As
                           Object, e As System.EventArgs) Handles B_Load.Click
    Dim FullText As String = ""
    For Each row As GridViewRow In GV_Comments.Rows
        Dim CB_Control As CheckBox = CType(row.FindControl("Comment_Select"),
                                           CheckBox)
        Dim Lbl_Control As Label= CType(row.FindControl("Label1"), Label)
        If CB_Control IsNot Nothing AndAlso CB_Control.Checked AndAlso Lbl_Control
           IsNot Nothing Then
            FullText = FullText &  Lbl_Control.Text & "<br/>"
        End If
    Next row
    CompiledText.Text = FullText.ToString
End Sub


这篇关于Gridview文本框在'findcontrol'上返回NULL值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 17:51