asp.net how to add items programmatically to detailsview

Posted by dotnet-practitioner on Stack Overflow See other posts from Stack Overflow or by dotnet-practitioner
Published on 2009-04-27T03:36:28Z Indexed on 2010/06/13 2:02 UTC
Read the original article Hit count: 384

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about detailsview