|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
reuse query results for multiple object populations? (and dynamic variable names?)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 thank you very much for any help. hi,
i dont know what u are returning from "myDBclass.GetNames(groupID)" so that i'm assuming that you are returing a datatable or dataset. in this case take a the return value in a related object and assigned it to every combo. thus your round trip to DB will be decreased. and your code will be little faster. if you are returning DataReader in that case you have to take all vaues from the Reader into an array or in DataTable and assigned it to all combos. in case of referencing an object, i would say create a procedure which takes an object ByRef and populate it. this could also reduce the code overhead. i dont know any other ways than this. i hope this will help you do optimize your code. Lucky Simon,
I never will use a refill in a going ASPNET application between postbacks. All was it only because of the fact that you don't know if somebody else has updated partially the resultset. The datasset is not for nothing serializable. In my opinion is saving it in a session.item the way to go. I hope this helps, Cor thank you both for replying,
i'll try both methods you mentioned and see how the results look trying to decrease DB calls and code. just didn't want to see the same block of code being repeated over and over :) i'm going to post another question about dynamic variable name referece in another thread to try and keep the topics clean here thanks again |
|||||||||||||||||||||||