Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2014-11-12
3
550 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:Mike Miller
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
jitendra patil earned 500 total points
ID: 40439290
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:Mike Miller
ID: 40440363
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
ID: 40444126
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

792 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