asp.net将许多下拉列表的模板字段项添加到detailsview控件

时间:2009-05-01 04:12:20

标签: asp.net drop-down-menu detailsview

如何以编程方式为详细信息视图中的每个下拉列表控件添加以下模板字段?

<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>    

1 个答案:

答案 0 :(得分:0)

可能是这样的:

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)