views:

545

answers:

2

I have the following code for each lookup table. So far I am doing copy/paste for each drop down list control. But I think there is a better way of doing this. I should be able to specify DataTextField, DataValueField, control names etc. Of course I will have to manually add configuration related database values on the database side like look up table, and other changes in the stored proc. But at the aspx page or .cs page, there has to be a better way then copy/paste..

                  </asp:TemplateField>                                                                           <asp:TemplateField HeaderText="Your Ethnicity">

' > ' ID="lblEthnicity">

Please let me know... Thanks

A: 

I think Custom control should help you to solve this problem.

Soul_Master
+1  A: 

To drive the content in the drop down controls from the database you can bind them using a number of different DataSource's depending on your architecture.

Here is a simple example (change list box to dropdownlist):

 <asp:SqlDataSource
      id="SqlDataSource1"
      runat="server"
      DataSourceMode="DataReader"
      ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
      SelectCommand="SELECT LastName FROM Employees">
  </asp:SqlDataSource>

  <asp:ListBox
      id="ListBox1"
      runat="server"
      DataTextField="LastName"
      DataSourceID="SqlDataSource1">
  </asp:ListBox>
Jon