Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: What am I missing? Dropdownlist won't fill from SQL stored proced ure


Message #1 by "Patterson, Stephanie L" <stephanie.l.patterson@i...> on Wed, 9 Oct 2002 09:45:05 -0700
What am I missing?  My DDL is empty! :(  Code is below.

Thanks in advance!
Stephanie


In the HTML:
    <ASP:DropDownList 
      id="ProdTypeList2" 
      runat="server" 
      DataSource='<%# DDLTable.DefaultView() %>' />

In the VB Codebehind:
  Dim strConnection As String
  Public DDLTable As DataTable

  ...

  Sub GetDDLdata()
    strConnection = "server=dev;user id=sa;password=;"
    strConnection += "database=ind_pdqrnet;"
    strConnection += "Connect Timeout=30"

    Dim objConnection As New SqlConnection(strConnection)
    Dim objDataAdapter As SqlDataAdapter
    Dim objCommand As SqlCommand
    objCommand = New SqlCommand("ddlProdCat", objConnection)
    objCommand.CommandType = CommandType.StoredProcedure

    Try
      objConnection.Open()
      con_open.Text = "Connection opened successfully.<br />"
      objDataAdapter.SelectCommand = objCommand
      objDataAdapter.Fill(DDLTable)
      objConnection.Close()
      con_close.Text = "Connection closed. <br />"
    Catch e As Exception
      con_open.Text = "Connection to product_data failed to open. <br />"
      con_close.Text = e.ToString()
    End Try
  End Sub      'GetDDLdata
Message #2 by =?iso-8859-1?Q?Lars_Gyldenk=E6rne?= <lgy@n...> on Wed, 9 Oct 2002 19:41:47 +0200
You have to bind the data to you controls either
ProdTypeList2.Databind() or if you have more contorls on your page 
Page.Databind()

Hope this helps

Lars


-----Original Message-----
From: Patterson, Stephanie L [mailto:stephanie.l.patterson@i...]
Sent: 9. oktober 2002 18:45
To: aspx_beginners
Subject: [aspx_beginners] What am I missing? Dropdownlist won't fill 
from SQL stored proced ure


What am I missing?  My DDL is empty! :(  Code is below.

Thanks in advance!
Stephanie


In the HTML:
    <ASP:DropDownList
      id=3D"ProdTypeList2"
      runat=3D"server"
      DataSource=3D'<%# DDLTable.DefaultView() %>' />

In the VB Codebehind:
  Dim strConnection As String
  Public DDLTable As DataTable

  ...

  Sub GetDDLdata()
    strConnection =3D "server=3Ddev;user id=3Dsa;password=3D;"
    strConnection +=3D "database=3Dind_pdqrnet;"
    strConnection +=3D "Connect Timeout=3D30"

    Dim objConnection As New SqlConnection(strConnection)
    Dim objDataAdapter As SqlDataAdapter
    Dim objCommand As SqlCommand
    objCommand =3D New SqlCommand("ddlProdCat", objConnection)
    objCommand.CommandType =3D CommandType.StoredProcedure

    Try
      objConnection.Open()
      con_open.Text =3D "Connection opened successfully.<br />"
      objDataAdapter.SelectCommand =3D objCommand
      objDataAdapter.Fill(DDLTable)
      objConnection.Close()
      con_close.Text =3D "Connection closed. <br />"
    Catch e As Exception
      con_open.Text =3D "Connection to product_data failed to open. <br 
/>"
      con_close.Text =3D e.ToString()
    End Try
  End Sub      'GetDDLdata

---
Beginning ASP.NET Databases using VB.NET 
http://www.wrox.com/ACON11.asp?ISBN=3D1861006195

Beginning ASP.NET Databases using C# 
http://www.wrox.com/ACON11.asp?ISBN=3D1861007418

These books look at how we can create data-centric ASP.NET
applications. Requiring some basic knowledge of ASP.NET,
Access and SQL the authors guide you through the process
of connecting and consuming information in a variety of
ways. They are packed full of excellent illustrative code
examples, demonstrating important fundamental principles.

  Return to Index