Repeater控制元件實現排序
阿新 • • 發佈:2019-01-25
<form id="form1" runat="server">
<table id="tblSort">
<tbody>
<asp:Repeater ID="ddllinputlist" OnItemCommand="ddllinputlist_ItemCommand" runat="server">
<HeaderTemplate>
<th class="tblSort_x enter_list_sort" style="cursor: pointer;">
<asp:LinkButton ID="ContractNo" runat="server" CommandName="ContractNo">合同編號</asp:LinkButton></th>
<th class="tblSort_x">客戶姓名</th>
<th class="tblSort_x">客戶手機號</th>
<th class="tblSort_x">投資產品</th>
<th class="tblSort_x">業務員姓名</th>
<th class="tblSort_x">業務員身份證號</th>
<th class="tblSort_d">金額(元)</th>
<th class="tblSort_d enter_list_sort" style="cursor: pointer;">
<asp:LinkButton ID="AddDate" runat="server" CommandName="AddDate">錄入時間</asp:LinkButton></th>
<th class="tblSort_x">稽核狀態</th>
<th class="tblSort_x">備註</th>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("ContractNo") %></td>
<td><%#Eval("CustomerName") %></td>
<td><%#Eval("CustomerPhone") %></td>
<td><%#((int)Eval("Productid") != 0)?Flatty.Library.Sys.DataAccess.Wq.ProductAdapter.Instance.LoadByid((int)Eval("Productid")).ProductName:""%></td>
<td><%#((int)Eval("Personnelid") != 0)?Flatty.Library.DataAccess.Wq.WqPersonnelAdapter.Instance.LoadByid((int)Eval("Personnelid")).Named:""%></td>
<td><%#((int)Eval("Personnelid") != 0)?Flatty.Library.DataAccess.Wq.WqPersonnelAdapter.Instance.LoadByid((int)Eval("Personnelid")).CardNumber:""%></td>
<td><%#Math.Round(Convert.ToDecimal(Eval("InvestAmount").ToString()),2) %></td>
<td><%#Eval("AddDate","{0:yyyy-MM-dd}") %></td>
<td><a <%#BindTitle(Eval("AuditState"))?" style='color:#f00;'": " style='color:#000;'"%>><%#Flatty.Common.Helper.EnumHelper.GetDescription<Flatty.Common.AuditState>((int)Eval("AuditState"))%></a></td>
<td class="tblSort_Remarks"><a href="#">備註</a><p><i></i><%#Eval("Remarks")%></p>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</table>
</form>
<div id="PageInfo" runat="server" class="anpager"></div>
private static DataSet dts = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (dts.Tables.Count == 0)
{
dts = FeatListAdapter.Instance.GetAllList();
if (dts.Tables[0].Rows.Count != 0)
{
PageInfo.InnerHtml = PageNums.GetPageNum(dts, ddllinputlist, 20, null); //傳入DataSet,DataList名稱和分頁大小
}
}
else
{
if (dts.Tables[0].Rows.Count != 0)
{
PageInfo.InnerHtml = PageNums.GetPageNum(dts, ddllinputlist, 20, null); //傳入DataSet,DataList名稱和分頁大小
}
}
}
}
/// <summary>
/// 排序事件
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
protected void ddllinputlist_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";
}
else
{
if (ViewState[e.CommandName.Trim()].ToString().Trim() == "ASC")
{
ViewState[e.CommandName.Trim()] = "DESC";
}
else
{
ViewState[e.CommandName.Trim()] = "ASC";
}
}
ViewState["text"] = lkbtnSort.Text;
ViewState["id"] = e.CommandName.Trim();
DataView dv = new DataView(dts.Tables[0]);
dv.Sort = e.CommandName.ToString().Trim() + " " + ViewState[e.CommandName.Trim()].ToString().Trim();
dts = new DataSet();
dts.Tables.Add(dv.ToTable());
PageInfo.InnerHtml = PageNums.GetPageNum(dts, ddllinputlist, 20, null); //傳入DataSet,DataList名稱和分頁大小
}
}