Subject: class file
Posted By: thas123 Post Date: 12/13/2006 2:45:30 AM
The below line set the text in the textbox inside the gridview

((TextBox)DtClass.FindMyControl(GridView,"TextBox1")).Text="hi";

Below is the code for finding the id of a control and doing an action with it,say finnding the textbox id inside a grid.


public static Control FindMyControl(Control c, string s)
        {
            Control found = null;
 
            for(int i = 0; i < c.Controls.Count; i++)
            {
                if(c.Controls[i].UniqueID.EndsWith(s)==true)
                {
                    found = c.Controls[i];
                    break;
                }
                else
                {
                    found = FindMyControl(c.Controls[i], s);
                    if(found != null)
                        break;
                }
            }
            return found;
        }
 
how do you convert the same code in vb.net.i did convert , but i am getting error of object reference not set to an instance of an object.
below is my vb code.

 Public Shared Function FindMyControl(ByVal c As Control, ByVal s As String) As Control
        Dim found As Control = Nothing
        Dim i As Integer = 0
        Do While (i < c.Controls.Count)
            If (c.Controls(i).UniqueID.EndsWith(s) = True) Then
                found = c.Controls(i)
                'TODO: Warning!!! break;If

            Else
                found = FindMyControl(c.Controls(i), s)
                If (Not (found) Is Nothing) Then
                    'TODO: Warning!!! break;If
                    GoTo p


                End If

            End If
            i = (i + 1)
        Loop
p:
        Return found
    End Function

Hope this is the right one.(Please tell me if any error is there above.im new to vb.net)

 CType(DtClass.FindMyControl(GridView1, "TextBox1"), TextBox).Text="hi"

while running the code im getting error object reference not sat to an instance of an object.




Go to topic 53367

Return to index page 95
Return to index page 94
Return to index page 93
Return to index page 92
Return to index page 91
Return to index page 90
Return to index page 89
Return to index page 88
Return to index page 87
Return to index page 86