请教GridView 排序,翻页问题.. 我现在使用的翻页和排序都是GridView自带的... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用viewstate保存你的排序字段,每次翻页重新绑定时,查询都order by该viewstate 请问用javascript该怎么实现?哪位大哥有没有实例... ps:不是js private void BindDG() { SqlConnection con=new SqlConnection("server=.;database=rmt2;uid=sa;pwd=000"); SqlDataAdapter sda=new SqlDataAdapter("select * from cityview",con); DataSet ds=new DataSet(); sda.Fill(ds,"city"); DataView dv=ds.Tables["city"].DefaultView; dv.Sort=this.DataGrid1.Attributes["SortExp"]+" "+this.DataGrid1.Attributes["SortDir"]; this.DataGrid1.DataSource=dv; this.DataGrid1.DataBind(); con.Close(); } private void Page_Load(object sender, System.EventArgs e) { if(!this.IsPostBack) { this.DataGrid1.Attributes["SortExp"]="provincename"; this.DataGrid1.Attributes["SortDir"]="asc"; this.BindDG(); } // 在此处放置用户代码以初始化页面 } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged); this.DataGrid1.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.DataGrid1_SortCommand); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) { this.DataGrid1.CurrentPageIndex=e.NewPageIndex; this.BindDG(); } private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) { if(e.SortExpression!=null && e.SortExpression==this.DataGrid1.Attributes["SortExp"]) { this.DataGrid1.Attributes["SortDir"]=(this.DataGrid1.Attributes["SortDir"]=="asc"?"desc":"asc"); } else { this.DataGrid1.Attributes["SortExp"]=e.SortExpression; this.DataGrid1.Attributes["SortDir"]="asc"; } this.BindDG(); } } 简单问题,进者有分,在线等,马上结,是关于datatalbe的 【☆☆☆有关异常☆☆☆】 请问如何让自定义控件大小随页面变化而变化? 如何将两个值传到另一个页面? 简单问题,如何得到post过来的表单数据? 两张表中的不同两列怎样显示在一个DataGrid的同一列中? 问一个关于asp和.net程序的转换的问题 asp.net中,上传文件时,怎么取得该文件的实际类型 哪里有Solpartmenu这个菜单控件下载啊 WEB页面上的报表 一个Tree View 绑定的问题(急.快回) 请高手指点下
private void BindDG()
{
SqlConnection con=new SqlConnection("server=.;database=rmt2;uid=sa;pwd=000");
SqlDataAdapter sda=new SqlDataAdapter("select * from cityview",con);
DataSet ds=new DataSet();
sda.Fill(ds,"city");
DataView dv=ds.Tables["city"].DefaultView;
dv.Sort=this.DataGrid1.Attributes["SortExp"]+" "+this.DataGrid1.Attributes["SortDir"];
this.DataGrid1.DataSource=dv;
this.DataGrid1.DataBind(); con.Close();
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
this.DataGrid1.Attributes["SortExp"]="provincename";
this.DataGrid1.Attributes["SortDir"]="asc";
this.BindDG();
}
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.DataGrid1.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.DataGrid1_SortCommand);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
this.BindDG();
} private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
if(e.SortExpression!=null && e.SortExpression==this.DataGrid1.Attributes["SortExp"])
{
this.DataGrid1.Attributes["SortDir"]=(this.DataGrid1.Attributes["SortDir"]=="asc"?"desc":"asc");
}
else
{
this.DataGrid1.Attributes["SortExp"]=e.SortExpression;
this.DataGrid1.Attributes["SortDir"]="asc";
}
this.BindDG();
}
}