Solved

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

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

11 Experts available now in Live!

Get 1:1 Help Now