views:

1285

answers:

1

How can I add the following templatefield programmatically for each of the dropdownlist control inside the details view?

<asp:TemplateField HeaderText="Your Gender">
    <EditItemTemplate>
        <asp:DropDownList ID="ddlGender" runat="server" 
                        DataSourceid="ddlDAGender"
                        DataTextField="Gender" DataValueField="GenderID"
                        SelectedValue='<%#Bind("GenderID") %>'
            >
         </asp:DropDownList>
    </EditItemTemplate>

    <ItemTemplate >
        <asp:Label Runat="server" Text='<%# Bind("Gender") %>' ID="lblGender"></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
A: 

Maybe something like:

Dim tc As New System.Web.UI.WebControls.TemplateField

tc.HeaderTemplate = Page.LoadTemplate("Controls/DatagridCheckboxColumnHeader.ascx")
tc.ItemTemplate = Page.LoadTemplate("controls/DatagridCheckboxColumn.ascx")

tc.HeaderText = "Select"

grdView.Columns.Insert(0, tc)
steve