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

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

Posted on 2007-11-30
1
7,697 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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 …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

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