views:

952

answers:

1

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 HeaderText="Your Ethnicity">
<EditItemTemplate>
<asp:DropDownList ID="ddlEthnicity" runat="server" 
DataSourceid="ddlDAEthnicity"
DataTextField="Ethnicity" DataValueField="EthnicityID"
SelectedValue='<%#Bind("EthnicityID") %>'
>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate >
<asp:Label Runat="server" Text='<%# Bind("Ethnicity") %>' 
ID="lblEthnicity">
</asp:Label>
</ItemTemplate>
</asp:TemplateField>

Please let me know... Thanks

A: 

hook to item created or data bound event, do IF else loop to find the DDL in the details view template , then programmatically hook it to Data source of your choice and set the selected value to be the Key data item of the detail view.

hope this helps.