【发布时间】:2017-09-21 13:46:36
【问题描述】:
这是我添加带有箭头的 gridview 的代码。Gridview 按升序和降序排序,但我无法添加箭头。
protected void grdInformation_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row != null && e.Row.RowType == DataControlRowType.Header)
{
foreach (TableCell cell in e.Row.Cells)
{
if (cell.HasControls())
{
LinkButton button = cell.Controls[0] as LinkButton;
HtmlGenericControl gv = new HtmlGenericControl("div");
Label lnkName = new Label();
lnkName.Text = button.Text;
if (button != null)
{
Image imageSort = new Image();
imageSort.ImageUrl = "~/images/asc.png";
if (grdInformation.SortExpression == button.CommandArgument)
{
if (grdInformation.SortDirection == SortDirection.Ascending)
{
imageSort.ImageUrl = "~/images/desc.png";
}
else
{
imageSort.ImageUrl = "~/images/asc.png";
}
}
gv.Controls.Add(lnkName);
gv.Controls.Add(imageSort);
button.Controls.Add(gv);
}
}
}
}
}
}}
Dono 我哪里出错了,我参加了一个排序事件,这是我对 gridview 进行排序的代码,它工作正常,但我无法向 girdview 添加箭头,上面我已经尝试过但它没有添加我的箭头,我如何添加箭头??
我尝试了一些文章,但我无法添加带有升序和降序的箭头,gridview 在单击标题行时正在排序,但需要向用户显示他可以根据升序和降序箭头进行排序......
protected void grdInformation_Sorting(object sender, GridViewSortEventArgs e)
{
if (CurrentSortExpression == e.SortExpression.ToString())
{
if (CurrentSortDirection == "asc")
CurrentSortDirection = "desc";
else
CurrentSortDirection = "asc";
}
else
{
CurrentSortExpression = e.SortExpression.ToString();
CurrentSortDirection = "asc";
}
if (e.SortExpression.Trim() == this.SortField)
{
this.sortDirection = (this.sortDirection == "DESC" ? "ASC" : "DESC");
}
else
{
this.sortDirection = "ASC";
}
ViewState["SortDirection"] = this.sortDirection;
this.SortField = e.SortExpression;
Bindinfo(GetInformation(ddlStatus.SelectedValue, ddlGroups.SelectedValue));
}
请帮忙??
【问题讨论】:
标签: c# asp.net sorting gridview