⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sort.aspx

📁 C#开发者可使用的经典案例集,源自于ASP.NET经典范例50讲
💻 ASPX
字号:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>
  <head>
    <title>DataView Sort Demo</title>
    <script language="C#" runat="server" >

    public void Page_Load()
    {
      string dataSource = "Data Source=localhost;";
      string security = "user id=sa; password=;";
      string initialCatalog = "initial catalog=pubs;";
      string cnnString = dataSource + security + initialCatalog;
      SqlConnection connection = new SqlConnection(cnnString);

      string strSql = "select au_id,au_fname,au_lname,phone,state from [authors]";
      SqlCommand command = new SqlCommand(strSql, connection);
      SqlDataAdapter adapter = new SqlDataAdapter();
      adapter.SelectCommand = command;
      DataTable dataTable = new DataTable();

      try
      {
        connection.Open();
        adapter.Fill(dataTable);
      }
      catch(SqlException e)
      {
        Response.Write(e.ToString());
      } 
      finally
      {
        connection.Close();
      }
      if(!IsPostBack)
        txtSortField.Text = "au_id";

      DataView dataView = new DataView(dataTable);
      dataView.Sort = txtSortField.Text;
      grid1.DataSource=dataView;
      grid1.DataBind();
    }
    </script>
  </head>

  <body>
  <form id="form1" runat="server">
    <h3>DataView Sort Demo</h3>
    <asp:DataGrid id="grid1" runat="server" />
    排序字段<asp:TextBox id="txtSortField" runat="server"/>
    <asp:Button id="Button1" runat="server" Text="排序"/>
  </form>
  </body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -