I am trying to figure out how to populate my dropdown list with data from my table. What happens is I call a method that expects an id by using this method I want to keep looping through the recordset and populate my dropdown list with teh values I require.
Here is teh code I have attempted to write this code appears in my page load
ddlVersions.Items.Clear()Dim _CVersion As Content = ContentManager.GetContentVersionList(Page.Request.Params("PID"))
Dim Version As ContentFor Each Version In _CVersion
ddlVersions.DataTextField = "CoPgVersion"
ddlVersions.DataValueField = "CoPgID"
ddlVersions.DataBind()
Next
Here is my method
Public Shared Function GetContentVersionList(ByVal CoPgID As Integer) As Content
' Get the list of Content form the datastore
Dim _Data As SqlDataReader
Dim _Content As New Content_Data = SqlHelper.ExecuteReader(ConfigurationSettings.AppSettings("DataStoreConnection"), CommandType.StoredProcedure, "Content_get", New SqlParameter("@dotnet.itags.org.CoPgID", CoPgID))
While _Data.Read
_Content = PopulateObjectFromSqlDataReader(_Data)
End While_Data.Close()
Return _Content
End Function
My stored procedure is basically the following SQL Statement
Select * from content where CoPgID = @dotnet.itags.org.CoPgID
I am simply getting teh syntax wrong but I am unsure on how to correctly code the dropdownlist so it populates.
While I am here once I get the drop down list to work is there a way I can make the drop down list highlight as if selected the most current record.
Basically the dropdownlist will display all teh version of my content if I am at version 4 I want version for to appear along with the rest of teh versions but for it to be select rather than "Please Select" is this doable?
I look forward to any help one may be able to give
Kind Regards
BradHi I will try to help a bit but take it with reservation as I am just beginner using Matrix which generates code for me, but just to say that when I was populating drop down list following instructions from the matrix book I did not loop through the recordset.
Steps were:
-to create function with sql statement in it and reterning the recordset
-to assign this function to data source of drop down list so:
dropdownlist.DataSource=above function
dropdownlist.DataBind()
these 2 lines are putting your recordset in the list already but they are always within some event
for example page load event
i hope this helps
anqa
Anga is quite correct. This is the way to bind data to controls in ASP.NET.
Seethis example on LearnASP.com for more details.
0 comments:
Post a Comment