做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

gridview自動排序示例分享

來源:懂視網 責編:小采 時間:2020-11-27 22:40:08
文檔

gridview自動排序示例分享

gridview自動排序示例分享:示例如下:前臺 代碼如下:<%@ Page Language=C# AutoEventWireup=true CodeFile=Default.aspx.cs Inherits=_Default %> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transition
推薦度:
導讀gridview自動排序示例分享:示例如下:前臺 代碼如下:<%@ Page Language=C# AutoEventWireup=true CodeFile=Default.aspx.cs Inherits=_Default %> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transition

示例如下:前臺

代碼如下:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>無標題頁</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True" OnSorting="GridView1_Sorting">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
                <asp:BoundField DataField="id" HeaderText="ID" SortExpression="id" />
                <asp:BoundField DataField="name" HeaderText="NAME" SortExpression="name" />
                <asp:BoundField DataField="age" HeaderText="AGE" SortExpression="age" />
            </Columns>
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
    </div>
    </form>
</body>
</html>

前臺注意點:
需要對GridView啟用AllowSorting、設置OnSorting事件,對需要排序的列設定SortExpression屬性。

后臺

代碼如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // 設定初始排序參數值

            // 錯誤的屬性設置方法:SortExpression、SortDirection均是GridView只讀屬性,無法直接賦值。
            //this.GridView1.SortExpression = "id";
            //this.GridView1.SortDirection = "ASC";

            // 正確的屬性設置方法
            this.GridView1.Attributes.Add("SortExpression", "id");
            this.GridView1.Attributes.Add("SortDirection", "ASC");

            // 綁定數據源到GridView
            this.BindGridView();
        }
    }

    /// <summary>
    /// GridView排序事件
    /// </summary>
    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        // 從事件參數獲取排序數據列
        string sortExpression = e.SortExpression.ToString();

        // 假定為排序方向為“順序”
        string sortDirection = "ASC";

        // “ASC”與事件參數獲取到的排序方向進行比較,進行GridView排序方向參數的修改
        if (sortExpression == this.GridView1.Attributes["SortExpression"])
        {
            //獲得下一次的排序狀態
            sortDirection = (this.GridView1.Attributes["SortDirection"].ToString() == sortDirection ? "DESC" : "ASC");
        }

        // 重新設定GridView排序數據列及排序方向
        this.GridView1.Attributes["SortExpression"] = sortExpression;
        this.GridView1.Attributes["SortDirection"] = sortDirection;

        this.BindGridView();
    }

    /// <summary>
    /// 綁定到GridView
    /// </summary>
    private void BindGridView()
    {
        // 獲取GridView排序數據列及排序方向
        string sortExpression = this.GridView1.Attributes["SortExpression"];
        string sortDirection = this.GridView1.Attributes["SortDirection"];

        // 調用業務數據獲取方法
        DataTable dtBind = this.getDB();

        // 根據GridView排序數據列及排序方向設置顯示的默認數據視圖
        if ((!string.IsNullOrEmpty(sortExpression)) && (!string.IsNullOrEmpty(sortDirection)))
        {
            dtBind.DefaultView.Sort = string.Format("{0} {1}", sortExpression, sortDirection);
        }

        // GridView綁定并顯示數據
        this.GridView1.DataSource = dtBind;
        this.GridView1.DataBind();
    }

    /// <summary>
    /// 獲取數據源的方法
    /// </summary>
    /// <returns>數據源</returns>
    private DataTable getDB()
    {
        DataTable dt = new DataTable();

        dt.Columns.Add("id");
        dt.Columns.Add("name");
        dt.Columns.Add("age");

        dt.Rows.Add(new object[] { "000001", "hekui", "26" });
        dt.Rows.Add(new object[] { "000002", "zhangyu", "26" });
        dt.Rows.Add(new object[] { "000003", "zhukundian", "27" });
        dt.Rows.Add(new object[] { "000004", "liyang", "25" });
        dt.Rows.Add(new object[] { "000005", "caili", "27" });

        return dt;
    }
}

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

gridview自動排序示例分享

gridview自動排序示例分享:示例如下:前臺 代碼如下:<%@ Page Language=C# AutoEventWireup=true CodeFile=Default.aspx.cs Inherits=_Default %> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transition
推薦度:
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 文化| 漳州市| 平潭县| 上高县| 景泰县| 金寨县| 织金县| 油尖旺区| 靖远县| 田林县| 甘洛县| 乌拉特后旗| 贵溪市| 临高县| 砚山县| 松滋市| 五指山市| 库伦旗| 盐亭县| 寿宁县| 高台县| 屏东县| 留坝县| 瑞安市| 五大连池市| 康马县| 陕西省| 武义县| 克什克腾旗| 沙坪坝区| 叶城县| 化州市| 长垣县| 内乡县| 雷州市| 大同市| 平利县| 陵水| 怀安县| 肥西县| 黄骅市|