asp:Repeater數據排序

<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();
            //數據綁定
            }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章