Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 30, 2012 07:59 PM by grundebar
Apr 30, 2012 03:32 PM|LINK
I have a SQL table that contains three items (e.g. Yes, No, Maybe So) and I create a dynamic drop down DropDownList to record the response for multiple multiple questions.
In the code behind I am using the following (Example 1) to populate a DropDownList from an SQL table to and ItemTemplate of a DataGrid.
(Example 2) is used in the Code page to retrieve the list. The problem is that I have to repeat the same DropDownList (with different ID's - Comment1, Comment2, Comment3...etc.) 81 times.
If I use the same DataSource="<%#
LoadComments() %>" for each of the 80 instances, each iteration
of the list adds the original 3 items in the list to the next list, where by the 80th instance there are 240 items listed in the drop down, from a list that only has three items.
Is there a way to use this single instance to populate each of the 80 instances of the list? I know I can hard code 80 instances of the list with List Item, but I would
prefer to use the database to populate the list, as later additions to the list, do not to be modified for each of the 80 lists...
Thanks for your assistance, in advance!!
mySettingsComments = AppSettings
strConnComments = mySettingsComments("connString")
strComments ="SELECT Comment_ID, Comment_Code, Comment_Description "
"FROM Hanes_Comments "
"Order By Comment_Code ASC"
New SqlDataAdapter(strComments, objConnComments)
Apr 30, 2012 07:59 PM|LINK
You can declare a page level variable to store the results for your query and then reuse it.
Protected dsResults As DataSet
Protected Function LoadComments()
Dim dsComments As DataSet
'Add other validation here, eg - check for tables and rows, etc.
If Not IsNothing(dsResults) Then
dsComments = dsResults
'go to db and perform your sql command
If you need to persist this dataset across postbacks, you can look at moving it to viewstate or session as well.