我有一个数据网格,其中有许多列,其中2个可排序,日期和时间。量。只要单击任一列,我的代码就可以重新排序行(asc-to-desc,desc-to-asc)。但是,我在每个列标题中都有3个图标 - 向上箭头,向下箭头和显示两者的默认图标。
如何在页面加载时显示默认图标,向上箭头仅显示订单何时上升,下降时显示下降?刚才我显示了所有3个图标,任何修复此问题的尝试都会引发错误。
以下是datagrid的相关部分(显示Amount列):
<asp:datagrid id="dgCurrentRequests" runat="server" Width="100%" Font-Size="XX-Small" Font-Names="Verdana"
AutoGenerateColumns="False" DataKeyField="RequestID" AllowSorting="true" OnSortCommand="OnSort">
<FooterStyle Font-Bold="True"></FooterStyle>
<HeaderStyle Font-Size="XX-Small" Font-Names="Verdana" Font-Bold="True" ForeColor="White" BackColor="#006699"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="BranchName" HeaderText="Branch"></asp:BoundColumn>
<asp:BoundColumn DataField="AccountantName" HeaderText="Requested By"></asp:BoundColumn>
<asp:BoundColumn DataField="Supplier" HeaderText="Pay To"></asp:BoundColumn>
<asp:TemplateColumn SortExpression="DisplayAmount">
<HeaderTemplate>
<asp:LinkButton id="DisplayAmount" runat="server" Text="Amount"
CommandName="Sort" CommandArgument="DisplayAmount"></asp:LinkButton>
<img runat="server" id="AmountAscending" src="..\images\asc.png" />
<img runat="server" id="AmountDefault" src="..\images\default.png" />
<img runat="server" id="AmountDescending" src="..\images\desc.png" />
</HeaderTemplate>
<itemtemplate>
<asp:Label id="DisplayAmount" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"DisplayAmount") %>' ></asp:Label>
</itemtemplate>
</asp:TemplateColumn>
以下是重新排序网格的代码隐藏:
public void FillCurrentRequests()
{
Accountant theAccountant=(Accountant)Session["Accountant"];
ArrayList requests = new ArrayList();
requests = theAccountant.GetExternalRoylineRequests(dbConnString, "Pending", (string)ViewState["sortColumn"], (string)ViewState["sortDirection"], 100);
dgCurrentRequests.DataSource = requests;
dgCurrentRequests.DataBind();
}
public void OnSort(Object sender, DataGridSortCommandEventArgs e)
{
if (((string) ViewState["sortColumn"]).Equals(e.SortExpression))
{
if (((string) ViewState["sortDirection"]) == "ASC")
{
ViewState["sortDirection"] = "DESC";
}
else
{
ViewState["sortDirection"] = "ASC";
}
}
else
{
ViewState["sortDirection"] = "ASC";
}
ViewState["sortColumn"] = e.SortExpression;
FillCurrentRequests();
}
I have attempted to declare the images then use them in a method to set the default icon, but it throws a SystemNullException:
protected Image AmountAscending;
protected Image AmountDefault;
protected Image AmountDescending;
protected Image DateRequestedAscending;
protected Image DateRequestedDefault;
protected Image DateRequestedDescending;
//
public void ResetSortOrder()
{
AmountAscending.Visible = false;
...
}
就好像应用程序看不到cs文件实体'AmountAscending'等是aspx文件中这些图像的id。
请帮忙!如何在aspx.cs页面中使用这些图像?