<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; } }