在网格视图标头中添加下拉菜单



我是ASP.net的新手,正在Gridview控件的标题字段下尝试添加dropdownlist和搜索文本框。

<asp:GridView ID="EmpGridView" runat="server" AutoGenerateColumns="false"
        DataKeyNames="EMPLOYEEID" 
        AllowSorting="True" AllowPaging="true" PageSize="50"
        OnPageIndexChanging="EmpGridView_PageIndexChanging" style="margin-right: 52px" OnSelectedIndexChanged="EmpGridView_SelectedIndexChanged"   
    > 
        <Columns>
            <asp:BoundField DataField="EMPLOYEEID"
            HeaderText="Employee ID" ReadOnly="true"
            SortExpression="EMPLOYEEID" />

            <asp:BoundField DataField="PERSONNAME"
            HeaderText="Person Name" ReadOnly="true"
            SortExpression="PERSONNAME" />
            <asp:BoundField DataField="DIVISIONNAME"
            HeaderText="Division Name" ReadOnly="true"
            SortExpression="DIVISIONNAME" />

                    <asp:BoundField DataField="DESIGNATION" 
                            HeaderText="Designation" ReadOnly="true" 
                            SortExpression="DESIGNATION"     
                         />
            <asp:BoundField DataField="CNIC"
            HeaderText="CNIC" ReadOnly="true"
            SortExpression="CNIC" />
        </Columns>

    </asp:GridView>

我想要跟随

EMPLOYEEID            PERSONNAME              DIVISIONNAME          <----HeaderText
TextBox control       TextBox Control         DropDownlist control  <------aspcontrols
 ..data                ..data                   ..data              <------ rest is db
 ..data                ..data                   ..data

这意味着我也希望我的标签与我的asp.net控件在一起我该怎么做?

到目前为止,我试着跟随,但不知道该把它放在哪里?因为如果我单独添加它,那么每个控件都有我不想要的行,并且边界字段标签不允许它在其中。

              <asp:TemplateField>
                  <ItemTemplate>
                      <asp:TextBox ID="searchBox" runat="server" />
                  </ItemTemplate>
              </asp:TemplateField>

您需要使用TemplateField的HeaderTemplate将控件放置在标头上

<asp:TemplateField SortExpression="PERSONNAME">
    <HeaderTemplate>
        <asp:Literal runat="server">Person Name</asp:Literal>
        <asp:TextBox runat="server" ID="searchBox"></asp:TextBox>
    </HeaderTemplate>
    <ItemTemplate>
        <asp:Literal runat="server" Text='<%# Bind("PERSONNAME") %>'></asp:Literal>
    </ItemTemplate>
</asp:TemplateField>

最新更新