| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 352 人关注过本帖
标题:分页代码错在那
只看楼主 加入收藏
luo113927
Rank: 1
等 级:新手上路
帖 子:173
专家分:0
注 册:2006-3-15
收藏
 问题点数:0 回复次数:1 
分页代码错在那

protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button btnFrontPage;
protected System.Web.UI.WebControls.Button btnNextPage;
protected System.Web.UI.WebControls.DataGrid DataGrid1;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
SqlConnection conn = new SqlConnection("server=.; uid=sa; pwd=; database=luo_news");
SqlCommand cmd = new SqlCommand("select num = COUNT(*) from db_article",conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleRow);
if(dr.Read())
{
this.DataGrid1.VirtualItemCount = (int)dr["num"];
}
this.Label1.Text = dr["num"].ToString();
dr.Close();
conn.Close();

BindToSource("fristPage");
}
}

private void NavigateToPage(object sender, System.EventArgs e)
{
string btnInfo = ((Button)sender).CommandName;
switch(btnInfo)
{
case "frontPage":if(this.DataGrid1.CurrentPageIndex > 0)
this.DataGrid1.CurrentPageIndex -= 1;
else
return;
break;

case "nextPage":if(this.DataGrid1.CurrentPageIndex < this.DataGrid1.PageCount - 1)
this.DataGrid1.CurrentPageIndex += 1;
else
return;
break;
}

BindToSource(btnInfo);
}

private void BindToSource(string btnInfo)
{
SqlConnection conn = new SqlConnection("server=.; uid=sa; pwd=; database=luo_news");
SqlCommand cmd = null;

switch(btnInfo)
{
case "fristPage":cmd = new SqlCommand("select top 2 title, articleid, writer, addtime from db_article",conn);
break;

case "frontPage":cmd = new SqlCommand("select top 2 title, articleid, writer, addtime from db_article where articleid>=@ID",conn);
cmd.Parameters.Add("@ID",SqlDbType.Int,8).Value = ViewState[(this.DataGrid1.CurrentPageIndex-1).ToString()];
break;

case "nextPage":cmd = new SqlCommand("select top 2 title, articleid, writer, addtime from db_article where articleid>@ID",conn);
cmd.Parameters.Add("@ID",SqlDbType.Int,8).Value = this.DataGrid1.Items[1].Cells[0].Text;
break;
}

conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
this.DataGrid1.DataSource = dr;
this.DataGrid1.DataBind();
dr.Close();
conn.Close();

ViewState[this.DataGrid1.CurrentPageIndex.ToString()] = this.DataGrid1.Items[0].Cells[0].Text;

}

当点激下一页时出错提示是“输入字符串的格式不正确”,大家帮帮偶看看代码有没问题

搜索更多相关主题的帖子: 代码 
2006-08-11 10:24
luo113927
Rank: 1
等 级:新手上路
帖 子:173
专家分:0
注 册:2006-3-15
收藏
得分:0 
有没有人啊!!!~~~
2006-08-11 11:15
快速回复:分页代码错在那
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031214 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved