asp:Repeater数据排序

来源:互联网 发布:淘宝店铺封了怎么激活 编辑:程序博客网 时间:2024/05/17 23:55

<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();            //数据绑定            }
0 0
原创粉丝点击