Solved

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

Posted on 2014-11-12
3
510 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
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:mwmiller78
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

770 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