dataview.sort()排序

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:03   1355   0

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication3._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>s 13 欧拉拉</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataGrid ID ="dgclass" runat ="server" AllowSorting ="true" OnSortCommand ="sortcolumn" />
</div>
</form>
</body>
</html>

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Data.SqlClient;

namespace WebApplication3
{
public partial class _Default : System.Web.UI.Page
{
public string strviewstring = "number";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
strviewString = "name";
SetData();
}

}

private void SetData()
{
String strconnection = "server=.;database=class;integrate security=true;";
SqlConnection objconnection = new SqlConnection(strconnection );
String strsql = "SELECT * FROM student ";

SqlDataAdapter objadapter = new SqlDataAdapter(strsql, objconnection);
DataSet objdataset = new DataSet();
objadapter.Fill(objdataset, "classbiao");
DataTable classbiao = objdataset.Tables["classbiao"];

DataView dvview = new DataView(classbiao);
dvview.Sort=strviewstring();


dgclass.DataSource = dvview;
dgclass.DataBind();
}
private void sortcolumn(object sender, DataGridSortCommandEventArgs e)
{
if (e.SortExpression == "phone")
strviewstring = "name,phone";
else
strviewstring = e.SortExpression;
SetData();
}
}
}
有错误的 发现错误木有啊

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP