private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
sqlConn = ConfigurationSettings.AppSettings["connK12SQLStr"];
myConnection = new SqlConnection(sqlConn);
if(!Page.IsPostBack)
{
//ExpertView数据绑定
dgDataBind();
}
PageNum.Attributes.Add("onkeydown", "javascript:if(13 == window.event.keyCode) {document.all.ImgGo.click(); return false;}"); }
private void dgDataBind()
{
//string sqlConn = ConfigurationSettings.AppSettings["connK12SQLStr"];
//SqlConnection myConnection = new SqlConnection(sqlConn);
string sqlStr = "SELECT NewsID, NewsTitle FROM News_Web WHERE ColID = 2 ORDER BY InputDateTime DESC";
SqlDataAdapter myCommand = new SqlDataAdapter(sqlStr, myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "NewsInfo"); recordCount = ds.Tables[0].Rows.Count;
//获取当前的页数
pageCount = (int)Math.Ceiling( recordCount * 1.0 / PageSize);
//避免纪录从有到无时,并且已经进行过反页的情况下CurrentPageIndex > PageCount出错
if(recordCount ==0)
{
this.dgNewsInfo.CurrentPageIndex = 0;
}
else if(this.dgNewsInfo.CurrentPageIndex >= pageCount)
{
this.dgNewsInfo.CurrentPageIndex = pageCount - 1;
} dgNewsInfo.DataSource = new DataView(ds.Tables[0]);
dgNewsInfo.DataBind();
NavigationStateChange();
} public void NavigationStateChange()
{
if( PageCount <= 1 )//( RecordCount <= PageSize )//小于等于一页
{
this.LBtnFirst.Enabled = false;
this.LBtnPrev.Enabled = false;
this.LBtnNext.Enabled = false;
this.LBtnLast.Enabled = false;
}
else //有多页
{
if( PageIndex == 0 )//当前为第一页
{
this.LBtnFirst.Enabled = false;
this.LBtnPrev.Enabled = false;
this.LBtnNext.Enabled = true;
this.LBtnLast.Enabled = true;
}
else if( PageIndex == PageCount - 1 )//当前为最后页 
{
this.LBtnFirst.Enabled = true;
this.LBtnPrev.Enabled = true;
this.LBtnNext.Enabled = false;
this.LBtnLast.Enabled = false;    
}
else //中间页
{
this.LBtnFirst.Enabled = true;
this.LBtnPrev.Enabled = true;
this.LBtnNext.Enabled = true;
this.LBtnLast.Enabled = true;

}
if(RecordCount == 0)//当没有纪录时DataGrid.PageCount会显示1页
this.LtlPageCount.Text = "0";
else
this.LtlPageCount.Text = PageCount.ToString();
if(RecordCount == 0)
this.LtlPageIndex.Text = "0";
else
this.LtlPageIndex.Text = (PageIndex + 1).ToString();//在有页数的情况下前台显示页数加1
//this.LtlPageSize.Text = PageSize.ToString();
//this.LtlRecordCount.Text = RecordCount.ToString();
} private void LBtnNavigation_Click(object sender, System.EventArgs e)
{
LinkButton btn = (LinkButton)sender;
switch(btn.CommandName)
{
case "first":
PageIndex = 0;
break;
case "prev"://if( PageIndex > 0 )
PageIndex = PageIndex - 1;
break;
case "next"://if( PageIndex < PageCount -1)
PageIndex = PageIndex + 1;
break;
case "last":
PageIndex = PageCount - 1;
break;
}
dgDataBind();             

// 总页数
public int PageCount
{
get{return this.dgNewsInfo.PageCount;}
} //页大小
public int PageSize
{
get{return this.dgNewsInfo.PageSize;}
} //页索引,从零开始
public int PageIndex
{
get{return this.dgNewsInfo.CurrentPageIndex;}
set{this.dgNewsInfo.CurrentPageIndex = value;}
} // 纪录总数 public int RecordCount
{
get{return recordCount;}
set{recordCount = value;}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dgNewsInfo.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgNewsInfo_ItemDataBound);
this.LBtnFirst.Click += new System.EventHandler(this.LBtnNavigation_Click);
this.LBtnPrev.Click += new System.EventHandler(this.LBtnNavigation_Click);
this.LBtnNext.Click += new System.EventHandler(this.LBtnNavigation_Click);
this.LBtnLast.Click += new System.EventHandler(this.LBtnNavigation_Click);
this.ImgGo.Click += new System.Web.UI.ImageClickEventHandler(this.ImgGo_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void ImgGo_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
//需验证输入为数值。
try
{
Convert.ToInt32(PageNum.Text.Trim());
}
catch
{
PageIndex = 0;
dgDataBind();
return;
}
if((Convert.ToInt32(PageNum.Text.Trim())>0) && (Convert.ToInt32(PageNum.Text.Trim())<=PageCount))
{
PageIndex = Convert.ToInt32(PageNum.Text.Trim())-1;
dgDataBind();         
}
else
{
PageIndex = 0;
dgDataBind();
}
} private void dgNewsInfo_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex != -1)
{
e.Item.Cells[0].Text = (this.dgNewsInfo.CurrentPageIndex * this.dgNewsInfo.PageSize + e.Item.ItemIndex + 1).ToString() + ". ";
}
}以上是主要源码,不知为何,点击ImgGo(imageButton)时序号正常显示,可是如何在textBox框上回车时序号就消失了。大虾们,帮忙呀!