Link to home
Start Free TrialLog in
Avatar of Member_2_1242703
Member_2_1242703

asked on

ASP.NET(VB) accessing controls in a GridView Row

I'm trying to access controls inside a Gridview. It does not like this line:
Dim repeater As Repeater = GridView1.SelectedRow.FindControl("Repeater1")
I suppose because it's not a selected row. What should it be? Here's the entire code...

    Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
        For Each GridViewRow In GridView1.Rows
            Dim repeater As Repeater = GridView1.SelectedRow.FindControl("Repeater1")
            For Each item In repeater.Items
                Dim separator As TextBox = item.findcontrol("tbSeparator")
                Dim sepList As ListBox = item.findcontrol("lbSeparator")
                If sepList.Items.Contains(item.separator.Text) Then
                     'do something
                Else
                   
                End If
            Next
        Next
    End Sub

Open in new window


How do I access the controls inside the GridView Row?
ASKER CERTIFIED SOLUTION
Avatar of jitendra patil
jitendra patil
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Member_2_1242703
Member_2_1242703

ASKER

Right direction. It's not liking this line now:

Dim sepList As ListBox = item.findcontrol("lbSeparator")

Open in new window


Returning: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.ListItem'
its because you are trying to access item value of a list box,

first try to find  the control within the foreach loop and if the control is of type listbox typecast the same in a listbox object.

you must find the control inside of repeater and cast the control to listbox again, to get the selected value you need to again loop through the items of listview. or something like this approach could do the trick.

hope this helps.