Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating DropDownList

Status
Not open for further replies.

spaulding

Technical User
Jan 10, 2001
123
US
I'm trying to populate a dropdownlist using a stored procedure and am doing something wrong (I'm still fairly new at this). I'm borrowing this sub almost directly from 4guysfromrolla, and when I run it, I get no error messages, but the dropdownlist is blank. I've checked the stored proc in query analyzer using the my test parameters (which are successfully displayed in lblRequestDate.Text)and the results are as expected, so I think I'm either skipping a step or doing something wrong. In either case, I'd appreciate any help given.
The stored procedure is:

CREATE PROCEDURE dbo.sp_ListAvailSub
@TeacherID nvarchar(3),
@SubDate datetime
AS
SELECT dbo.Sub_PersInfo.SubID, dbo.Sub_PersInfo.Name_F + ' ' + dbo.Sub_PersInfo.Name_L as SubName, dbo.Teacher_Course.INSTR_ID
FROM dbo.Teacher_Course INNER JOIN
dbo.Sub_QualInfo ON dbo.Teacher_Course.Course_Grade = dbo.Sub_QualInfo.SubQuals INNER JOIN
dbo.Sub_SchoolInfo ON dbo.Sub_QualInfo.SubID = dbo.Sub_SchoolInfo.SubID AND
dbo.Teacher_Course.CAMPUS_ID = dbo.Sub_SchoolInfo.School INNER JOIN
dbo.Sub_PersInfo ON dbo.Sub_QualInfo.SubID = dbo.Sub_PersInfo.SubID
WHERE (dbo.Teacher_Course.INSTR_ID = @teacherid) AND (dbo.Sub_PersInfo.SubID NOT IN
(SELECT dbo.Sub_PersInfo.SubID
FROM dbo.Sub_AssignedDate INNER JOIN
dbo.Sub_PersInfo ON dbo.Sub_AssignedDate.SubID = dbo.Sub_PersInfo.SubID
WHERE (dbo.Sub_AssignedDate.SubAssignedDate = @SubDate)))
GO
The code is below

Sub PopulateDropDownList(ByVal teacherid, ByVal requestdate)

Dim cmdFindAvailSub As SqlCommand
Dim daAvailSub As SqlDataAdapter
Dim dsAvail As New DataSet
Dim strsql As String



lblRequestDate.Text = "Data from PDDL: " & teacherid & " " & requestdate 'these parameters are successfully sent from the calling procedure

SqlConnection1.Open()
Try


cmdFindAvailSub = New SqlCommand("sp_listavailsub", SqlConnection1)


daAvailSub = New SqlDataAdapter
daAvailSub.SelectCommand = cmdFindAvailSub
daAvailSub.SelectCommand.Parameters.Add("@teacherid", teacherid)
daAvailSub.SelectCommand.Parameters.Add("@subdate", requestdate)
daAvailSub.SelectCommand.CommandType = CommandType.StoredProcedure

daAvailSub.Fill(dsAvail, "AvailSub")


TempDataView = dsAvail.Tables("AvailSub")


Catch ex As Exception
lblSql.Text = "Sorry, there was an error." & " Error: " & ex.ToString
End Try

End Sub

<asp:DropDownList id=ddlAvailSub runat="server" DataSource="<%# TempDataView %>" DataTextField="SubName" DataValueField="SubID">
</asp:DropDownList>
 
You are not binding your dropdownlist anywhere in the code:
Code:
yourddl.datasource = TempDataView
yourddl.textfield = "some col from view"
yourddl.valuefield = "some col from view"
'You can set the above properties in the property window in VS

Then bind it:
yourddl.DataBind()

Jim
 
Heres a simple example..

Dim cnVendor As SqlConnection = New SqlConnection

Dim cmdVendor As New SqlCommand("Populate_Vendors", cnVendor)

cmdVendor.CommandType = CommandType.StoredProcedure

cnVendor.Open()

cboVendor.DataSource = cmdVendor.ExecuteReader

cboVendor.DataTextField = "Vendor"
cboVendor.DataValueField = "Vendor"
cboVendor.DataBind()

cnVendor.Close()

 
well, as I said, I thought I was skipping a step. Thanks very much! Unfortunately, it was the obvious one. Doh!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top