• Asp.net Repeater 排序


    <table>
    <asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand"
                        OnItemDataBound="Repeater1_ItemDataBound">
            <HeaderTemplate>
                 <tr>
                      <th>
                           <asp:LinkButton ID="specialtyName" runat="server" CommandName="specialtyName">专业</asp:LinkButton>
                      </th>
                      <th>
                           <asp:LinkButton ID="classId" runat="server" CommandName="classId">班号</asp:LinkButton>
                      </th>
                      <th>
                           <asp:LinkButton ID="className" runat="server" CommandName="className">班级名称</asp:LinkButton>
                      </th>
                      <th>
                           <asp:LinkButton ID="grade" runat="server" CommandName="grade">年级</asp:LinkButton>
                      </th>
                      <th>
                           <asp:LinkButton ID="classNo" runat="server" CommandName="classNo">班级人数</asp:LinkButton>
                      </th>
                      <th>
                           <asp:LinkButton ID="length" runat="server" CommandName="length">学制</asp:LinkButton>
                      </th>
                      <th>
                           <asp:LinkButton ID="assistantId" runat="server" CommandName="assistantId">辅导员号</asp:LinkButton>
                      </th>
                      <th>
                           <asp:LinkButton ID="explain" runat="server" CommandName="explain">备注</asp:LinkButton>
                      </th>
                      <th>
                           <asp:LinkButton ID="action" runat="server" CommandName="action">操作</asp:LinkButton>
                      </th>
                 </tr>
            </HeaderTemplate>
            <ItemTemplate>
                 <tr>
                      <td>
                           <%# eval("specialtyName")%>
                      </td>
                      <td>
                           <%# eval("classId")%>
                      </td>
                      <td>
                           <%# eval("className") %>
                      </td>
                      <td>
                           <%# eval("grade") %>
                      </td>
                      <td>
                           <%# eval("classNo")%>
                      </td>
                      <td>
                           <%# eval("length") %>
                      </td>
                      <td>
                           <%# eval_r("assistantId")%>
                      </td>
                      <td>
                           <%# eval("explain")%>
                      </td>
                      <td>
                           <a href="#">删除</a>
                      </td>
                 </tr>
            </ItemTemplate>
    </asp:Repeater>
    </table>
      后台代码:
        protected void Page_Load(object sender, EventArgs e)
        {
             //这里是将数据库的数据绑定到repeater控件上,由于代码因工程而异,所以就不写了
             //绑定返回类型为DataTable dt
             GetData=dt.DefaultView;
        }
         protected void Repeater1_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.Text = ViewState["text"].ToString();
                    }
                }
            }
         protected void Repeater1_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();
                    DataView dv = GetData;
                    dv.Sort = e.CommandName.ToString().Trim() + " " + ViewState[e.CommandName.Trim()].ToString().Trim();
                    Repeater1.DataSource = dv;
                    Repeater1.DataBind();
                }
            }
         private DataView GetData
            {
                get
                {
                    return Cache["_data"] as DataView;
                }
                set
                {
                    Cache["_data"] = value;
                }
            }
     
  • 相关阅读:
    4.手工备份恢复关闭数据库的完全和不完全恢复(练习3、4)
    1.Oracle10g安装
    5.手工备份恢复打开数据库的备份与恢复(练习5、6)
    每天做好这些动作减肥瘦身不是梦 健康程序员,至尚生活!
    常搓八个部位可以防衰老 健康程序员,至尚生活!
    简单实用:可以祛斑的食物 健康程序员,至尚生活!
    谁都会做:简单易行的祛斑法 健康程序员,至尚生活!
    谁都可以做几分钱打造完美DIY面膜 健康程序员,至尚生活!
    一些护肤细节 健康程序员,至尚生活!
    生吃蔬菜健康轻松瘦身 健康程序员,至尚生活!
  • 原文地址:https://www.cnblogs.com/WangYunyun/p/3353408.html
Copyright © 2020-2023  润新知