datagridview标头过滤器 [英] datagridview header filter

查看:95
本文介绍了datagridview标头过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试通过使用标题中的下拉菜单来创建我的datagridview过滤器.我在此站点上找到了一个解决方法为此处的帖子,但是它要求我拥有Ajax控制工具包,但我无法在公司计算机上下载该工具包.还有其他解决方案吗?

请注意,我不是一个强大的程序员,因此请在您的答复中进行详细说明.

另请注意,gridview数据源与代码来自其他服务器.

预先感谢,
Sean8084

I''ve been trying to make my datagridview filter by using a drop down in the header. I found a post on this site that had a solution Here, but it required me to have the ajax control toolkit which I am not permitted to download on the company computer. Are there any other solutions to this problem?

Please note that I am not a strong programmer yet so please be detailed in your replies.

Please also note that the gridview datasource is from a different server than the code.

Thanks in advance,
Sean8084

推荐答案

Sean,我们需要在ASP .NET中模拟功能性ajax控件工具包

将示例代码与EmployeeID和Name放在这里.

Sean, we need to simulate the functionality ajax control toolkit in ASP .NET

Herez the sample code with EmployeeID and Name.

<body>
    <form id="form1" runat="server">
    <div>
      <table style="width: 640px" border="0" cellpadding="0" cellspacing="6" class="GridviewTable">
        <tr >
            <td style="width: 120px">
                Employee ID
            </td>
            <td style="width: 120px">
                Employee Name
            </td>
         </tr>
          <tr >
                <td style="width: 120px;">
                    <asp:TextBox ID="txtEmpId" runat="server" Width="75px"></asp:TextBox>
                    <asp:Button ID="btnEmpId" runat="server" Text="IDFilter" onclick="btnIdClick" />
                </td>
                <td style="width: 120px;">
                    <asp:TextBox ID="txtEmpName" runat="server" Width="75px"></asp:TextBox>
                    <asp:Button ID="btnEmpName" runat="server" Text="NameFilter" onclick="btnNameClick" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:GridView ID="gvEmp" runat="server" AutoGenerateColumns="False" Width="640px" ShowHeader="False" >
                        <Columns>
                            <asp:BoundField DataField="EmpId" ItemStyle-Width="120px" >
                            <ItemStyle Width="120px"></ItemStyle>
                            </asp:BoundField>
                            <asp:BoundField DataField="EmpName" ItemStyle-Width="120px" >
                            <ItemStyle Width="120px"></ItemStyle>
                            </asp:BoundField>
                        </Columns>
                    </asp:GridView>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>



在System.Data.DataTable背后的代码中起主要作用.生成本地数据表并在单击过滤器按钮事件期间更改结果集.



In code behind System.Data.DataTable plays the major role. Generate the local data table and change the result set during filter button clicked event.

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        EmpTable = new EmpTable();
        empTable = CreateDataTable();
        Session["EmpTable"] = empTable;

        this.gvEmp.DataSource = ((DataTable)Session["EmpTable"]).DefaultView;
        this.gvEmp.DataBind();
    }
}

private DataTable CreateDataTable()
{
    DataTable myDataTable = new DataTable();
    DataColumn myDataColumn;

    myDataColumn = new DataColumn();
    myDataColumn.DataType = Type.GetType("System.String");
    myDataColumn.ColumnName = "EmpId";
    myDataTable.Columns.Add(myDataColumn);


    myDataColumn = new DataColumn();
    myDataColumn.DataType = Type.GetType("System.String");
    myDataColumn.ColumnName = "EmpId";
    myDataTable.Columns.Add(myDataColumn);

    myDataTable.Rows.Add("111", "aaaaaa");

    return myDataTable;
}

protected void btnIdClick(object sender, EventArgs e)
{
    if (txtEmpId.Text.ToString().Trim() != "")
    {
        DataTable dt = (DataTable)Session["EmpTable"];
        var linquery = from tbl in dt.AsEnumerable()
                    where tbl.Field("EmpId").StartsWith(txtProductId.Text.ToString().Trim())
                    select t;
        DataTable dtable = new DataTable();
        dtable = linquery.CopyToDataTable();
        this.gvEmp.DataSource = dtable;
        this.gvEmp.DataBind();
    }
    else
    {
        this.gvEmp.DataSource = ((DataTable)Session["EmpTable"]).DefaultView;
        this.gvEmp.DataBind();
    }
}


DataGridView过滤器弹出窗口 [ ^ ]
具有内置过滤器功能的DataGrid [具有过滤功能的Datagridview [
DataGridView Filter Popup[^]
DataGrid with built-in filter functionality[^]
Datagridview with filtering capability[^]


这篇关于datagridview标头过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆