Solved

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

Posted on 2014-11-12
3
462 Views
Last Modified: 2014-11-14
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?
0
Comment
Question by:mwmiller78
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Jitendra Patil earned 500 total points
Comment Utility
change the code as below

For Each row As GridViewRow In GridView1.Rows

 Dim repeater As Repeater = row.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

hope this helps.
0
 

Author Comment

by:mwmiller78
Comment Utility
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'
0
 
LVL 12

Expert Comment

by:Jitendra Patil
Comment Utility
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.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now