0

有人可以告诉我如何对数据表列值应用过滤器,如下所示是数据表的列值现在在我的网格标题中我有一个下拉列表,其中包含上述列(如 sd、tf、er)的唯一值。现在我希望数据表使表值按下拉列表选定值分组。

所以我的痛苦是我无法按列值对数据表的值进行分组。

分组值必须位于下表的顶部。

  protected void ddlSortBy_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)(sender);
        string ddlValue = ddl.SelectedValue;
        customerDetailGrid.Sort(ddlValue, SortDirection.Ascending);
    }
    protected void customerDetailGrid_Sorting(object sender, GridViewSortEventArgs e)
    {
        SqlCommand cmd = new SqlCommand("PopulateCustomer");
        cmd.CommandType = CommandType.StoredProcedure;
        DataTable dtSortTable = DB.ExecuteDataTableCommand(cmd);//customerDetailGrid.DataSource as DataTable;

        if (dtSortTable != null)
        {
            DataView dvSortedView = new DataView(dtSortTable);
            dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection);
            customerDetailGrid.DataSource = dvSortedView;
            customerDetailGrid.DataBind();
        }
    }



    private static string getSortDirectionString(SortDirection sortDireciton)
    {
        string newSortDirection = String.Empty;
        if (sortDireciton == SortDirection.Ascending)
        {
            newSortDirection = "ASC";
        }
        else
        {
            newSortDirection = "DESC";
        }
        return newSortDirection;
    }
4

0 回答 0