Solved

Loop through rows to get control value within nested gridview ASP.NET 2.0

Posted on 2007-11-30
1
7,637 Views
Last Modified: 2013-11-26
Scenario: Gridview with employee, nested gridview with tasks that require completion, an item template within nested gridview that has a dropdown box where the user selects whether the task is completed, in process, not started, etc. An update button in the employee item tempate field (in same cell as nested gridview) that houses the nested gridview. When the update button is clicked, I want to iterate through the nested gridview and get the new value of the dropdownlist and send it to the database.

 Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim gvInside As GridView = CType(FindControl("gvTasks"), GridView)
        Dim iStatus As Integer
        Dim StatusBox As DropDownList
        For Each row As GridViewRow In gvInside.Rows
            StatusBox = CType(FindControl("ddCompletionStatus"), DropDownList)
            iStatus = StatusBox.SelectedValue
        Next
    End Sub
The code above generates the following error: System.NullReferenceException was unhandled by user code   Message="Object reference not set to an instance of an object."

Any help is appreciated. Thank you!
 
0
Comment
Question by:cmcormick
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 125 total points
ID: 20382269
You need to use FindControl with the Row.  You would need to find out what the current row for the outer grid is, and then get a reference to the inside GridView.

One possibility:




Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim gvInside As GridView = CType(gvOutSide.Rows(0).FindControl("gvTasks"), GridView)

        Dim iStatus As Integer

        

        For Each row As GridViewRow In gvInside.Rows

            Dim StatusBox As DropDownList = CType(row.FindControl("ddCompletionStatus"), DropDownList)

            iStatus = StatusBox.SelectedValue

        Next

    End Sub

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

20 Experts available now in Live!

Get 1:1 Help Now