您的位置:首页 > 编程语言 > ASP

asp:Repeater数据排序

2015-08-04 10:20 501 查看
<asp:Repeater ID="rptList" runat="server" OnItemCommand="rptList_ItemCommand"

OnItemDataBound="rptList_ItemDataBound">

<HeaderTemplate>

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="msgtable">

<tr>

<th width="100px">

<asp:LinkButton ID="CardAddNo" runat="server" CommandName="CardAddNo">单号</asp:LinkButton>

</th>

<th width="60px" align="center">

<asp:LinkButton ID="CardType" runat="server" CommandName="CardType">卡类型</asp:LinkButton>

</th>

<th width="70px">

<asp:LinkButton ID="CustomerNo" runat="server" CommandName="CustomerNo">卡号</asp:LinkButton>

</th>

<th width="60px" align="center">

<asp:LinkButton ID="Name" runat="server" CommandName="Name">姓名</asp:LinkButton>

</th>


protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
if (ViewState["id"] != null)
{
LinkButton lkbtnSort = (LinkButton)e.Item.FindControl(ViewState["id"].ToString().Trim());
lkbtnSort.ForeColor = System.Drawing.Color.Red;
lkbtnSort.Text = ViewState["text"].ToString();
}
}
}


protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
LinkButton lkbtnSort = (LinkButton)e.Item.FindControl(e.CommandName.Trim());
if (ViewState[e.CommandName.Trim()] == null)
{
ViewState[e.CommandName.Trim()] = "ASC";
lkbtnSort.Text = lkbtnSort.Text + "▲";
}
else
{
if (ViewState[e.CommandName.Trim()].ToString().Trim() == "ASC")
{
ViewState[e.CommandName.Trim()] = "DESC";
if (lkbtnSort.Text.IndexOf("▲") != -1)
lkbtnSort.Text = lkbtnSort.Text.Replace("▲", "▼");
else
lkbtnSort.Text = lkbtnSort.Text + "▼";
}
else
{
ViewState[e.CommandName.Trim()] = "ASC";
if (lkbtnSort.Text.IndexOf("▼") != -1)
lkbtnSort.Text = lkbtnSort.Text.Trim().Replace("▼", "▲");
else
lkbtnSort.Text = lkbtnSort.Text + "▲";
}
}
ViewState["text"] = lkbtnSort.Text;
ViewState["id"] = e.CommandName.Trim();
//数据绑定
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asp-Repeat 数据排序