a way to reuse query results for multiple object populations?

msimon7

Member
Joined
Jan 13, 2006
Messages
9
Programming Experience
10+
hello,
i have a form where there are multiple dropdown lists that will all be populated from the same initial data query.
i have a vb class defined to make the stored proc call and that returns a dataset. in my codebehind, i have in an "If Not Page.IsPostBack" block with statements that populate each of the dropdown lists. there could be up to 10 dropdowns lists used, which means the current way i'm doing it i'd have 10 sets of the same code, only difference would be the drop down object name.

is this the only way to do this? would be nice to reuse the results somehow, not have to call the stored proc function each time.

myDBclass is only dimensioned once, but the code sets will be repeated up to 10 times
each "set" of code is:
drop1.DataSource = myDBclass.GetNames(groupID)
drop1.DataTextField = "Name"
drop1.DataValueField = "UserId"
drop1.DataBind()


drop2.......
drop3.......
etc

have another question related to my handling of these very similar dropdown lists
what is a syntax example for using dynamic code to reference object names - i assume you do this?
example psuedo code...

while i < 11
loop
"drop"+i.SelectedIndex = 0
i = i + 1
end loop


new to vb/asp.net. thanks very much for any help!
 
i think this may give u some help

to loop through a control in a panel
VB.NET:
Dim i As Integer
        Dim lbl As Label
        For Each lbl In Me.Panel1.Controls
            lbl.Text = DS.Tables(0).Rows(i).Item(0).ToString
            i += 1
        Next
 
thank for the reply, i think what you are saying is what i'm looking for, but i not sure as i'm pretty new to vb.net

in other languages you can build a string, by using concatenation, and then interpret that string as an actual variable OR build the whole statement line and then execute that string as a statement.

like in javascript there is a function eval() whose parameter is a string. so results of that call eval("string_to_evaluate") gets executed or interpreted as if you had type the string out directly.​

if what i'm saying/asking is what you replied, sorry for asking again. didn't quite follow your example.
i think i'm not following what these lines truly represent
Me.Panel1.Controls
DS.Tables(0).Rows(i).Item(0).ToString (i think i follow this one, but not sure)

any futher help clearing this concept up for me would truly be appreciated!
thanks again
 
it was just an example to show u howto loop through controls on a container

here i have looped in the labels that exist on a panel on the form
VB.NET:
For Each lbl In Me.Panel1.Controls

sorry just to complicated
VB.NET:
            lbl.Text = DS.Tables(0).Rows(i).Item(0).ToString
consider it that i change the label text prperty
VB.NET:
            lbl.Text = "label" & i

ur second q's to assign a control the way u want assign a control some property is not possible in vb.net(i have not come across suchthg)
 
Back
Top