0

I have asp.net application. where on 2 web pages i have dropdown on each page. i want to populate the User list in drop down. so as usual i wrote the method FillUserDropDown() in common helper class.

and accessing this method on both page loads. but I am passing the Drop down control as parameter to this method so that method appears generic for all type of fill drop downs. Is this standard way? my seniors are avoiding me to passing the control as parameters.

So what is the best practice for this scenario? Please guide me.

Red Swan
  • 15,157
  • 43
  • 156
  • 238

2 Answers2

0

To databind is better. But this is also acceptable just that you can let ASP.NET 'fill' it in automatically if you databind (it will generate the code for you). Return a datatable or list and and specify declarivly the binding.

Also tell your seniors that it's ok to do that too. If you've written the code already leave it.

jkj
  • 36
  • 1
  • Thanks for guidance @jkj. for now i am using Fill () ,by gettin LIST<> and populating drop down. Data binding is good way i think. but how if need to populate the grid in custom way (using item templates) . then i strictly need this fill method. right? but seniors are saying it may harmful for state of control. is that true? – Red Swan Mar 05 '11 at 09:34
  • Look at this thread: http://stackoverflow.com/questions/275194/formatting-databinder-eval-data - use DataBinder class. – jkj Mar 05 '11 at 09:39
0

Call Method By this way

FillDropDown(DropDownID, selectListItemText)

Set Below Code In your commonfile

DropDownID.DataTextField = "TextFieldName"; DropDownID.DataValueField = "ValueFieldName"; DropDownID.DataSource = DatasourceName; DropDownID.DataBind();

if (includeSelectItem) { DropDownID.Items.Insert(0, new ListItem(selectListItemText, selectListItemValue)); }

This way you can bind as you said above

sikender
  • 5,883
  • 7
  • 42
  • 80