我的DataGrid怎么突然不显示了? 不知刚才改了aspx文件中什么地方,DataGrid突然不显示了,输出一个空白页面,CS文件中的代码都仍然正常运行;aspx文件的设计页面,看起也很正常;在页面中,点右键-->查看源文件,看不到DataGrid的信息; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <%@ Register TagPrefix="dxwc" Namespace="DevExpress.Web.ASPxGrid" Assembly="DevExpress.Web.ASPxGrid, Version=1.5.0.1, Culture=neutral, PublicKeyToken=79868b8147b5eae4" %><%@ Page language="c#" Codebehind="mainfile.aspx.cs" AutoEventWireup="false" Inherits="htoa.WebForm1" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML> <HEAD> <title>WebForm1</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="C#" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> <LINK href="../Include/oa.css" rel="stylesheet"> <style type="text/css">BODY { MARGIN: 0px } BODY { FONT-SIZE: 12px } TD { FONT-SIZE: 12px } TH { FONT-SIZE: 12px } </style></HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" runat="server"> <table style="WIDTH: 99%" align="center" border="0"> <tr> <td> <asp:datagrid id="xpTable" style="Z-INDEX: 101; LEFT: 0px; TOP: 24px" runat="server" Width="100%" AutoGenerateColumns="False" HorizontalAlign="Center" Font-Size="8pt" Font-Name="Verdana" OnPageIndexChanged="xpTable_Page" PagerStyle-HorizontalAlign="Right" PagerStyle-Mode="NumericPages" PageSize="20" AllowPaging="True" AllowSorting="True" Font-Names="Verdana" BorderWidth="2px" CellPadding="3" BorderStyle="Ridge" BackColor="#F2F2F2" CellSpacing="1" GridLines="None"> <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#9471DE"></SelectedItemStyle> <HeaderStyle Wrap="False" HorizontalAlign="Center" ForeColor="Black" CssClass="ListTableHeader"></HeaderStyle> <Columns> <asp:BoundColumn Visible="False" DataField="Sort" SortExpression="Sort" HeaderText="序号"> <HeaderStyle Width="0px"></HeaderStyle> </asp:BoundColumn> <asp:BoundColumn DataField="CodeText" SortExpression="CodeText" HeaderText="编号"> <HeaderStyle Wrap="False" Width="100px"></HeaderStyle> </asp:BoundColumn> <asp:BoundColumn DataField="FileName" SortExpression="FileName" HeaderText="名称"></asp:BoundColumn> <asp:BoundColumn DataField="FileTitle" SortExpression="FileTitle" HeaderText="主题"></asp:BoundColumn> <asp:TemplateColumn SortExpression="IsRead" HeaderText="已读"> <HeaderStyle Wrap="False" Width="30px"></HeaderStyle> <ItemTemplate> <img src='imges/<%# DataBinder.Eval(Container.DataItem,"IsRead") %>.gif'> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn SortExpression="SecretNo" HeaderText="密级"> <HeaderStyle Wrap="False" Width="30px"></HeaderStyle> <ItemTemplate> <%# SecretNoToString((DataBinder.Eval(Container.DataItem,"SecretNo")).ToString()) %> </ItemTemplate> </asp:TemplateColumn> <asp:BoundColumn DataField="JbMan" SortExpression="JbMan" HeaderText="经办人"> <HeaderStyle Wrap="False" Width="70px"></HeaderStyle> </asp:BoundColumn> <asp:BoundColumn DataField="CompliteTime" SortExpression="CompliteTime" HeaderText="发布时间" DataFormatString="{0:yyyy-MM-dd hh:mm}"> <HeaderStyle Wrap="False" Width="120px"></HeaderStyle> <ItemStyle Wrap="False"></ItemStyle> </asp:BoundColumn> </Columns> <PagerStyle HorizontalAlign="Right" ForeColor="Black" CssClass="ListTableHeader" Mode="NumericPages"></PagerStyle> </asp:datagrid></td> </tr> <tr> <td> <p style="FONT-SIZE: 9pt" align="center"><asp:label id="lblPageCount" runat="server" Width="125px"></asp:label> <asp:label id="lblCurrentIndex" runat="server"></asp:label><asp:linkbutton id="btnFirst" onclick="PagerButtonClick" runat="server" Font-Name="verdana" Font-size="8pt" ForeColor="navy" CommandArgument="0"></asp:linkbutton> <asp:linkbutton id="btnPrev" onclick="PagerButtonClick" runat="server" Font-Name="verdana" Font-size="8pt" ForeColor="navy" CommandArgument="prev"></asp:linkbutton> <asp:linkbutton id="btnNext" onclick="PagerButtonClick" runat="server" Font-Name="verdana" Font-size="8pt" ForeColor="navy" CommandArgument="next"></asp:linkbutton> <asp:linkbutton id="btnLast" onclick="PagerButtonClick" runat="server" Font-Name="verdana" Font-size="8pt" ForeColor="navy" CommandArgument="last"></asp:linkbutton> <asp:label id="labGoto" runat="server" Width="40px">转到第:</asp:label> <asp:textbox id="txtDescPage" Width="29px" Font-Name="verdana" BorderStyle="Groove" Font-size="8pt" Runat="server"></asp:textbox><asp:label id="Label1" runat="server" Width="10px">页</asp:label> <asp:linkbutton id="btGoto" runat="server" Width="3px" Font-Name="verdana" Font-size="8pt" ForeColor="navy" CommandArgument="last">GO</asp:linkbutton></p> </td> </tr> </table> </form> <script language="C#" runat="server"> public string SecretNoToString(string SecretNo) { switch(int.Parse(SecretNo)){ case 0:{return("公开");break;} case 1:{return "普通";break;} case 2:{return "机密";break;} case 3:{return "绝密";break;} default:{return "普通";break;} } } </script> <script language="javascript"> function GridClick(row) { var table = row.parentElement; var i; for (i = 0; i < table.rows.length; i++) { table.rows[i].bgColor = "#F2F2F2"; } row.bgColor = "#ffffcc"; } </script> </body></HTML> using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;namespace htoa{ /// <summary> /// WebForm1 的摘要说明。 /// </summary> public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.Label lblPageCount; protected System.Web.UI.WebControls.Label lblCurrentIndex; protected System.Web.UI.WebControls.LinkButton btnFirst; protected System.Web.UI.WebControls.LinkButton btnPrev; protected System.Web.UI.WebControls.LinkButton btnNext; protected System.Web.UI.WebControls.LinkButton btnLast; protected System.Web.UI.WebControls.DataGrid xpTable; protected System.Web.UI.WebControls.Label labGoto; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.LinkButton btGoto; protected System.Web.UI.WebControls.TextBox txtDescPage; private DbObj db = new DbObj(); private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if(!Page.IsPostBack){ btnFirst.Text = "最首页"; btnPrev.Text = "前一页"; btnNext.Text = "下一页"; btnLast.Text = "最后页"; ViewState["SortDirection"]="ASC"; BindGrid(); } } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.btGoto.Click += new System.EventHandler(this.btGoto_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion public void BindGrid() { db.dt = new DataSet(); string strSql; strSql="select Sort,CodeText,[dbo].[GetIsRead](sort,'FlowFile','manager') as IsRead,FileName,FileTitle,SecretNo,JbMan,CompliteTime from dbo.FlowFile";// where " + Request["strSqlQuery"].ToString(); db.da = new System.Data.SqlClient.SqlDataAdapter(strSql, db.cn); db.OpenDb(); db.da.Fill(db.dt , "filelist"); Session["DV"]=db.dt.Tables[0].DefaultView; db.dt.Dispose(); db.da.Dispose(); db.cn.Close(); db.cn.Dispose(); } private void btGoto_Click(object sender, System.EventArgs e) { int intGotoPageCount; intGotoPageCount=int.Parse(txtDescPage.Text); if (xpTable.CurrentPageIndex!=intGotoPageCount-1){ if (!((intGotoPageCount>xpTable.PageCount) || (intGotoPageCount<0))){ xpTable.CurrentPageIndex =intGotoPageCount-1; } } } public void xpTable_Page(object sender, DataGridPageChangedEventArgs e) { int startIndex ; startIndex = xpTable.CurrentPageIndex * xpTable.PageSize; xpTable.CurrentPageIndex = e.NewPageIndex; //BindGrid(); //ShowStats(); } private void ShowStats() { lblCurrentIndex.Text = "当前第 " + (xpTable.CurrentPageIndex + 1).ToString() + " 页"; lblPageCount.Text = "总 " + ((DataView)xpTable.DataSource).Table.Rows.Count +" 条记录 共 " + xpTable.PageCount.ToString() + " 页"; } public void PagerButtonClick(object sender, EventArgs e) { string arg = ((LinkButton)sender).CommandArgument.ToString(); switch(arg) { case "next": if (xpTable.CurrentPageIndex < (xpTable.PageCount - 1)) { xpTable.CurrentPageIndex += 1; } break; case "prev": if (xpTable.CurrentPageIndex > 0) { xpTable.CurrentPageIndex -= 1; } break; case "last": xpTable.CurrentPageIndex = (xpTable.PageCount - 1); break; default: xpTable.CurrentPageIndex = System.Convert.ToInt32(arg); break; } //BindGrid(); //ShowStats(); } private void xpTable_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemIndex >= 0) { e.Item.Attributes["onClick"] = "javascript:GridClick(this)"; e.Item.Attributes["onMouseOver"] = "javascript:if (this.bgColor!='#ffffcc') this.bgColor='#0066ff';"; e.Item.Attributes["onMouseOut"] = "javascript:if (this.bgColor!='#ffffcc') this.bgColor='#F2F2F2';"; } } private void xpTable_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) { //this.xpTable.CurrentPageIndex=0; //属性SortField 存促排序的字段 SortField=e.SortExpression; //重新绑定DataGrid控件 //BindGrid(); //判断排序方向 if(ViewState["SortDirection"].ToString()!="ASC") { //如果是升序就改为降序 ViewState["SortDirection"]="ASC"; } else { //如果是降序就改为升序 ViewState["SortDirection"]="DESC"; } } private void xpTable_PreRender(object sender, System.EventArgs e) { //排序字段是 属性SortField存储的字段 DataView DV=(DataView)Session["DV"]; DV.Sort=SortField; try { //设定,排序表达式 DV.Sort=SortField + " " + ViewState["SortDirection"].ToString(); } catch { //不作任何处理,因为第一次加载,SortField 的属性是空(String.Empty) 会有错误 } this.xpTable.DataSource=DV; this.xpTable.DataBind(); ShowStats(); } //属性,SortField 用ViewState跟踪排序字段 string SortField { get { object o=ViewState["SortField"]; if(o==null) { //如果为空,返回空字符串 return String.Empty; } return (string)ViewState["SortField"]; } set { ViewState["SortField"]=value; } } }} page_load的时候没有装载数据源,datagrid就不会显示 cs文件中override protected void OnInit(EventArgs e){}中定义的事件代码都哪去了,确实没碰过cs文件,我补上试试 打错了,private void InitializeComponent(){ this.btGoto.Click += new System.EventHandler(this.btGoto_Click);this.Load += new System.EventHandler(this.Page_Load);}中的事件代码丢了,补上试试 补上private void InitializeComponent()中的代码,就好了.我就不明白,我只是调了一下.aspx文件的内容,当时DataGrid控件出了一下错,就及早撤回操作了,期间并没改碰过.cs文件,为什么会造成InitializeComponent()中丢失代码呢?是vs.net的bug吗?另外aspx中的代码经常变得乱乱了,要么全部左对齐,分好行,自动要么跑到一行上去了,这又是为什么? 好在这次是小玩要,如果是大项目,给vs.net随意某处搞掉一两行代码,那还了得扯得清?? ASP.NET多页面窗口如何隐藏地址 装enterprise library4.0 时出现 your system has not modify 怎么解决呀 如何按照输入的格式存入数据库后显示出来 xml+dataSet 我网站都是调用的静态方法,传到万网空间上后,SESSION总是失去,这是为什么 DataGrid分页怪异问题。 在线等待急求 如何判断一段字符串中是否包含着全角字符? 处理 URL 时服务器出错。请与系统管理员联系,一般问题出在哪?高手指点下 关于下拉菜单的问题? WebResponse 的奇怪错误 datalist 能否实现显示两排得功能
<%@ Page language="c#" Codebehind="mainfile.aspx.cs" AutoEventWireup="false" Inherits="htoa.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="../Include/oa.css" rel="stylesheet">
<style type="text/css">BODY { MARGIN: 0px }
BODY { FONT-SIZE: 12px }
TD { FONT-SIZE: 12px }
TH { FONT-SIZE: 12px }
</style>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" runat="server">
<table style="WIDTH: 99%" align="center" border="0">
<tr>
<td>
<asp:datagrid id="xpTable" style="Z-INDEX: 101; LEFT: 0px; TOP: 24px" runat="server" Width="100%"
AutoGenerateColumns="False" HorizontalAlign="Center" Font-Size="8pt" Font-Name="Verdana" OnPageIndexChanged="xpTable_Page"
PagerStyle-HorizontalAlign="Right" PagerStyle-Mode="NumericPages" PageSize="20" AllowPaging="True"
AllowSorting="True" Font-Names="Verdana" BorderWidth="2px" CellPadding="3" BorderStyle="Ridge"
BackColor="#F2F2F2" CellSpacing="1" GridLines="None">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#9471DE"></SelectedItemStyle>
<HeaderStyle Wrap="False" HorizontalAlign="Center" ForeColor="Black" CssClass="ListTableHeader"></HeaderStyle>
<Columns>
<asp:BoundColumn Visible="False" DataField="Sort" SortExpression="Sort" HeaderText="序号">
<HeaderStyle Width="0px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="CodeText" SortExpression="CodeText" HeaderText="编号">
<HeaderStyle Wrap="False" Width="100px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="FileName" SortExpression="FileName" HeaderText="名称"></asp:BoundColumn>
<asp:BoundColumn DataField="FileTitle" SortExpression="FileTitle" HeaderText="主题"></asp:BoundColumn>
<asp:TemplateColumn SortExpression="IsRead" HeaderText="已读">
<HeaderStyle Wrap="False" Width="30px"></HeaderStyle>
<ItemTemplate>
<img src='imges/<%# DataBinder.Eval(Container.DataItem,"IsRead") %>.gif'>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="SecretNo" HeaderText="密级">
<HeaderStyle Wrap="False" Width="30px"></HeaderStyle>
<ItemTemplate>
<%# SecretNoToString((DataBinder.Eval(Container.DataItem,"SecretNo")).ToString()) %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="JbMan" SortExpression="JbMan" HeaderText="经办人">
<HeaderStyle Wrap="False" Width="70px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="CompliteTime" SortExpression="CompliteTime" HeaderText="发布时间" DataFormatString="{0:yyyy-MM-dd hh:mm}">
<HeaderStyle Wrap="False" Width="120px"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="Black" CssClass="ListTableHeader" Mode="NumericPages"></PagerStyle>
</asp:datagrid></td>
</tr>
<tr>
<td>
<p style="FONT-SIZE: 9pt" align="center"><asp:label id="lblPageCount" runat="server" Width="125px"></asp:label>
<asp:label id="lblCurrentIndex" runat="server"></asp:label><asp:linkbutton id="btnFirst" onclick="PagerButtonClick" runat="server" Font-Name="verdana" Font-size="8pt"
ForeColor="navy" CommandArgument="0"></asp:linkbutton>
<asp:linkbutton id="btnPrev" onclick="PagerButtonClick" runat="server" Font-Name="verdana" Font-size="8pt"
ForeColor="navy" CommandArgument="prev"></asp:linkbutton>
<asp:linkbutton id="btnNext" onclick="PagerButtonClick" runat="server" Font-Name="verdana" Font-size="8pt"
ForeColor="navy" CommandArgument="next"></asp:linkbutton>
<asp:linkbutton id="btnLast" onclick="PagerButtonClick" runat="server" Font-Name="verdana" Font-size="8pt"
ForeColor="navy" CommandArgument="last"></asp:linkbutton>
<asp:label id="labGoto" runat="server" Width="40px">转到第:</asp:label>
<asp:textbox id="txtDescPage" Width="29px" Font-Name="verdana" BorderStyle="Groove" Font-size="8pt"
Runat="server"></asp:textbox><asp:label id="Label1" runat="server" Width="10px">页</asp:label>
<asp:linkbutton id="btGoto" runat="server" Width="3px" Font-Name="verdana" Font-size="8pt" ForeColor="navy"
CommandArgument="last">GO</asp:linkbutton></p>
</td>
</tr>
</table>
</form>
<script language="C#" runat="server">
public string SecretNoToString(string SecretNo) {
switch(int.Parse(SecretNo)){
case 0:{return("公开");break;}
case 1:{return "普通";break;}
case 2:{return "机密";break;}
case 3:{return "绝密";break;}
default:{return "普通";break;}
}
}
</script>
<script language="javascript">
function GridClick(row)
{
var table = row.parentElement;
var i;
for (i = 0; i < table.rows.length; i++)
{
table.rows[i].bgColor = "#F2F2F2";
}
row.bgColor = "#ffffcc";
}
</script>
</body>
</HTML>
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace htoa
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblPageCount;
protected System.Web.UI.WebControls.Label lblCurrentIndex;
protected System.Web.UI.WebControls.LinkButton btnFirst;
protected System.Web.UI.WebControls.LinkButton btnPrev;
protected System.Web.UI.WebControls.LinkButton btnNext;
protected System.Web.UI.WebControls.LinkButton btnLast;
protected System.Web.UI.WebControls.DataGrid xpTable;
protected System.Web.UI.WebControls.Label labGoto;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.LinkButton btGoto;
protected System.Web.UI.WebControls.TextBox txtDescPage;
private DbObj db = new DbObj(); private void Page_Load(object sender, System.EventArgs e) {
// 在此处放置用户代码以初始化页面 if(!Page.IsPostBack){
btnFirst.Text = "最首页";
btnPrev.Text = "前一页";
btnNext.Text = "下一页";
btnLast.Text = "最后页";
ViewState["SortDirection"]="ASC";
BindGrid();
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btGoto.Click += new System.EventHandler(this.btGoto_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion public void BindGrid() {
db.dt = new DataSet();
string strSql;
strSql="select Sort,CodeText,[dbo].[GetIsRead](sort,'FlowFile','manager') as IsRead,FileName,FileTitle,SecretNo,JbMan,CompliteTime from dbo.FlowFile";// where " + Request["strSqlQuery"].ToString();
db.da = new System.Data.SqlClient.SqlDataAdapter(strSql, db.cn);
db.OpenDb();
db.da.Fill(db.dt , "filelist"); Session["DV"]=db.dt.Tables[0].DefaultView;
db.dt.Dispose();
db.da.Dispose();
db.cn.Close();
db.cn.Dispose();
}
private void btGoto_Click(object sender, System.EventArgs e) {
int intGotoPageCount;
intGotoPageCount=int.Parse(txtDescPage.Text);
if (xpTable.CurrentPageIndex!=intGotoPageCount-1){
if (!((intGotoPageCount>xpTable.PageCount) || (intGotoPageCount<0))){
xpTable.CurrentPageIndex =intGotoPageCount-1;
}
}
}
public void xpTable_Page(object sender, DataGridPageChangedEventArgs e) {
int startIndex ;
startIndex = xpTable.CurrentPageIndex * xpTable.PageSize;
xpTable.CurrentPageIndex = e.NewPageIndex;
//BindGrid();
//ShowStats();
}
private void ShowStats() {
lblCurrentIndex.Text = "当前第 " + (xpTable.CurrentPageIndex + 1).ToString() + " 页";
lblPageCount.Text = "总 " + ((DataView)xpTable.DataSource).Table.Rows.Count +" 条记录 共 " + xpTable.PageCount.ToString() + " 页";
} public void PagerButtonClick(object sender, EventArgs e) {
string arg = ((LinkButton)sender).CommandArgument.ToString();
switch(arg) {
case "next":
if (xpTable.CurrentPageIndex < (xpTable.PageCount - 1)) {
xpTable.CurrentPageIndex += 1;
}
break;
case "prev":
if (xpTable.CurrentPageIndex > 0) {
xpTable.CurrentPageIndex -= 1;
}
break;
case "last":
xpTable.CurrentPageIndex = (xpTable.PageCount - 1);
break;
default:
xpTable.CurrentPageIndex = System.Convert.ToInt32(arg);
break;
}
//BindGrid();
//ShowStats();
}
private void xpTable_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {
if (e.Item.ItemIndex >= 0) {
e.Item.Attributes["onClick"] = "javascript:GridClick(this)";
e.Item.Attributes["onMouseOver"] = "javascript:if (this.bgColor!='#ffffcc') this.bgColor='#0066ff';";
e.Item.Attributes["onMouseOut"] = "javascript:if (this.bgColor!='#ffffcc') this.bgColor='#F2F2F2';";
}
} private void xpTable_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) {
//this.xpTable.CurrentPageIndex=0;
//属性SortField 存促排序的字段
SortField=e.SortExpression; //重新绑定DataGrid控件
//BindGrid();
//判断排序方向
if(ViewState["SortDirection"].ToString()!="ASC") {
//如果是升序就改为降序
ViewState["SortDirection"]="ASC";
}
else {
//如果是降序就改为升序
ViewState["SortDirection"]="DESC";
}
} private void xpTable_PreRender(object sender, System.EventArgs e) { //排序字段是 属性SortField存储的字段
DataView DV=(DataView)Session["DV"];
DV.Sort=SortField;
try {
//设定,排序表达式
DV.Sort=SortField + " " + ViewState["SortDirection"].ToString();
}
catch {
//不作任何处理,因为第一次加载,SortField 的属性是空(String.Empty) 会有错误
}
this.xpTable.DataSource=DV;
this.xpTable.DataBind();
ShowStats();
} //属性,SortField 用ViewState跟踪排序字段
string SortField {
get {
object o=ViewState["SortField"];
if(o==null) {
//如果为空,返回空字符串
return String.Empty;
}
return (string)ViewState["SortField"];
}
set {
ViewState["SortField"]=value;
}
} }
}
{
this.btGoto.Click += new System.EventHandler(this.btGoto_Click);
this.Load += new System.EventHandler(this.Page_Load);}
中的事件代码丢了,补上试试