有人可以告诉我如何在数据表列值上应用过滤器 如下所示是datatable的列值 现在在我的网格标题中,我有一个下拉列表,它具有上述列的唯一值,如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;
}