ADO.NET: Retrieve Data from DropDownList

Hi all,

I have 2 Stored Procedures that i have created which I have attached. I have a .aspx page that has a dropdown list and a gridview on the same page. What I'm trying to accomplish is for a user to select an ID from the dropdown and retrieved details within the GridView. Please see my user controls that I created below. I'm sure i'm missing something easy, but I can't find it.

DropDown Control Code:

<script runat="server">
    Protected Sub LoadSubnet(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
           
            ' Define data objects
           
            Dim conn As SqlConnection
            Dim subnetsComm As SqlCommand
           
            Dim reader As SqlDataReader

            ' Read the connection string from Web.config
            Dim connectionString As String = ConfigurationManager.ConnectionStrings("NNDS_IP").ConnectionString
           
            ' Initialize connection
            conn = New SqlConnection(connectionString)
           
            ' Create command for SubnetList
            subnetsComm = New SqlCommand("SelectSubnetList", conn)
            ' Specify we're calling a stored procedure
            subnetsComm.CommandType = System.Data.CommandType.StoredProcedure
                 
            ' Enclose database code in Try-Catch-Finally
            Try
                ' Open the connection
                conn.Open()
               
                ' Execute the subnet command
                reader = subnetsComm.ExecuteReader()
                ' Populate the list of subnets
                subnetsList.DataSource = reader
                subnetsList.DataValueField = "NET_ID"
                subnetsList.DataTextField = "NET_SUBNET"
                subnetsList.DataBind()
                ' Close the reader
                reader.Close()
             
            Finally
                ' Close the connection
                conn.Close()
            End Try
        End If
    End Sub
</script>

<asp:DropDownList ID="subnetsList" runat="server" AutoPostBack="True">
</asp:DropDownList>

GridView User Control:

<script runat="server">
    Protected Sub LoadList(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
           
            Dim conn As SqlConnection
            Dim ipComm As SqlCommand
            Dim adapter As SqlDataAdapter
            Dim location As DataSet = New DataSet("location")
 
            ' Read the connection string from Web.config
            Dim connectionString As String = ConfigurationManager.ConnectionStrings("NNDS_IP").ConnectionString
 
            ' Initialize connection
            conn = New SqlConnection(connectionString)
 
            ' Create command for Student
            ipComm = New SqlCommand("SelectIP", conn)
            ' Specify we're calling a stored procedure
            ipComm.CommandType = CommandType.StoredProcedure
 
            Try
                ' Open the connection
                conn.Open()
           
                ' Execute the command
                adapter = New SqlDataAdapter
                adapter.TableMappings.Add("Table", "location")
                adapter.SelectCommand = ipComm
                adapter.Fill(location)
               
                ipComm.Parameters.Add("@net_id", SqlDbType.Int)
               
           
                ' Display the requested data                    
                ipList.DataSource = location.Tables(0)
                ipList.DataBind()
             
            Finally
                ' Close the connection
                conn.Close()
            End Try
        End If
    End Sub
</script>

<asp:GridView ID="ipList" runat="server">
</asp:GridView>
SelectIP.txt
SelectSubnetList.txt
LVL 4
asp_net2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vs1784Commented:
You have to create an event for selectedindexchanged for dropdownloast.

In that event implementation, you can rebind your grid as per the selection.

Hope it helps

Thanks
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
asp_net2Author Commented:
vs1784,

Thanks for the example but it didn't help me much at all. Basically I have an .aspx page that contains two webparts. I have created two user controls per web part. The first webpart calls the selectsubnet stored procedure which populates the data. The second webpart should display the results from the dropdownlist into a gridview located within the second webpart.
0
vs1784Commented:
In that case you have to bubble the event. Means you have to pass event from one user control to another.

Hope it helps.

Thanks
0
asp_net2Author Commented:
Can you provide me an example with the code I supplied above? I have an idea what to do but not sure where I made my mistake at above in the code.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.