本篇文章為大家展示了如何分析ASP.NET GridView分頁與雙向排序,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
為華坪等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及華坪網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都做網(wǎng)站、網(wǎng)站建設(shè)、華坪網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
以下代碼提供一個(gè)ASP.NET GridView分頁,雙向排序,帶指示箭頭圖標(biāo)案例。
GridViewPage.aspx(才用后臺(tái)代碼綁定方式)
< form id="form1" runat="server"> < asp:GridView AutoGenerateColumns= "False " AllowPaging="true" AllowSorting="true" PageSize="5" ID="gvData" runat="server" BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4" GridLines="Horizontal" SkinID="GridViewSkin" OnPageIndexChanging="gvData_PageIndexChanging" OnSorting="gvData_Sorting" OnRowCreated= "gvData_RowCreated" > < Columns> < asp:BoundField DataField="name" HeaderText="姓名" SortExpression="name"/> < asp:BoundField DataField="time" HeaderText="時(shí)間" SortExpression="time"/> < asp:BoundField DataField="title" HeaderText="標(biāo)題" SortExpression="title"/> < asp:BoundField DataField="content" HeaderText="正文" SortExpression="content"/> < /Columns> < /asp:GridView> < /form>
ASP.NET GridView分頁代碼:GridViewPage.aspx.cs
public partial class GridViewPage : System.Web.UI.Page { SqlDataAdapter da = null; DataSet ds = null; private string gvSortExpression { get { if (ViewState["sortorder"] != null && ViewState["sortorder"].ToString() != string.Empty) { return ViewState["sortorder"].ToString(); } else { return ""; } } set { ViewState["sortorder"] = value; } } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { ViewState["sortorder"] = "name"; ViewState["orderdire"] = "asc"; Bind(); } } protected void gvData_PageIndexChanging(object sender, GridViewPageEventArgs e) { gvData.PageIndex = e.NewPageIndex; Bind(); } protected void gvData_Sorting(object sender, GridViewSortEventArgs e) { gvSortExpression = e.SortExpression; string spage = e.SortExpression; if (ViewState["sortorder"].ToString() == spage) { if (ViewState["orderdire"].ToString() == "desc") ViewState["orderdire"] = "asc"; else ViewState["orderdire"] = "desc"; } else { ViewState["sortorder"] = e.SortExpression; } Bind(); } private void Bind() { SqlConnection con = new SqlConnection(BookSystem.SQLSERVERCONNECTIONSTRING); string sql = "select name,time,title,content from guestbook"; da = new SqlDataAdapter(sql, con); con.Open(); ds = new DataSet(); da.Fill(ds); DataView view = ds.Tables[0].DefaultView; string sort = (string)ViewState["sortorder"] + " " + (string)ViewState["orderdire"]; view.Sort= sort; gvData.DataSource = view; gvData.DataBind(); con.Close(); } protected void ShowSortedIcon(GridView gvData, GridViewRow gvRow) { for (int index = 0; index < = gvData.Columns.Count - 1; index++) { if ((gvData.Columns[index].SortExpression == gvSortExpression) && (gvData.Columns [index].SortExpression != "")) { Image img = new Image(); if ((string)ViewState["orderdire"] == "desc") { img.ImageUrl = "~/Images/sortascending.gif"; img.ToolTip = "遞增排列"; } else { img.ImageUrl = "~/Images/sortdescending.gif"; img.ToolTip = "遞減排列"; } gvRow.Cells[index].Controls.Add(img); } } } protected void gvData_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { ShowSortedIcon(gvData, e.Row); } } }
上述內(nèi)容就是如何分析ASP.NET GridView分頁與雙向排序,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
文章名稱:如何分析ASP.NETGridView分頁與雙向排序
鏈接分享:http://jinyejixie.com/article16/ghhjgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、網(wǎng)站內(nèi)鏈、微信公眾號(hào)、網(wǎng)站收錄、網(wǎng)站營銷、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)