//Repeater分页控制显示方法
public void contrlRepeater(int userId)
{
string connectionString = ConfigurationManager.ConnectionStrings["db_health"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
string sql = "select * from health_user_followup_content where user_id=" + userId + "";
SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
DataSet ds = new DataSet();
sda.Fill(ds,"FollowContent");
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["FollowContent"].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 5;
pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;
rpUserList.DataSource = pds;
LabCountPage.Text = pds.PageCount.ToString();
labPage.Text = (pds.CurrentPageIndex + 1).ToString();
this.lbtnpritPage.Enabled = true;
this.lbtnFirstPage.Enabled = true;
this.lbtnNextPage.Enabled = true;
this.lbtnDownPage.Enabled = true;
if (pds.CurrentPageIndex < 1)
{
this.lbtnpritPage.Enabled = false;
this.lbtnFirstPage.Enabled = false;
}
if (pds.CurrentPageIndex == pds.PageCount - 1)
{
this.lbtnNextPage.Enabled = false;
this.lbtnDownPage.Enabled = false;
}
rpUserList.DataBind();
}pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;————刚点击进入页面时,为什么我这句会提示:”输入字符串的格式不正确”
public void contrlRepeater(int userId)
{
string connectionString = ConfigurationManager.ConnectionStrings["db_health"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
string sql = "select * from health_user_followup_content where user_id=" + userId + "";
SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
DataSet ds = new DataSet();
sda.Fill(ds,"FollowContent");
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["FollowContent"].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 5;
pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;
rpUserList.DataSource = pds;
LabCountPage.Text = pds.PageCount.ToString();
labPage.Text = (pds.CurrentPageIndex + 1).ToString();
this.lbtnpritPage.Enabled = true;
this.lbtnFirstPage.Enabled = true;
this.lbtnNextPage.Enabled = true;
this.lbtnDownPage.Enabled = true;
if (pds.CurrentPageIndex < 1)
{
this.lbtnpritPage.Enabled = false;
this.lbtnFirstPage.Enabled = false;
}
if (pds.CurrentPageIndex == pds.PageCount - 1)
{
this.lbtnNextPage.Enabled = false;
this.lbtnDownPage.Enabled = false;
}
rpUserList.DataBind();
}pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;————刚点击进入页面时,为什么我这句会提示:”输入字符串的格式不正确”
解决方案 »
- 初学ASP.NET,速成之路,不知从何开始
- 提取字符串内的内容
- 现在学习ASP.NET还需要学习 VBScript和 javascript 吗?
- 关于asp.net生成以后的静态页cookies问题
- 请问怎么设计一个EXCEL模板,并将该模板的数据通过ASP.net导入到Oracle呢
- asp.net2.0 gridview分页问题 在线等
- 初学者,盼望得到高手指教,关于页面中控件的透明问题
- (急)关于存储过程中调用已有的存储过程
- 用ASP.net做wap的朋友请进,我有个问题想请教各位大侠
- 高手请帮忙!!!HELP 关于OWC的
- asp.net下jmail存储附件问题
- DataTable拆分成2个DataTable分别绑定到GridView的问题,求进。。。
pds.CurrentPageIndex =(this.labPage.Text==null?1:("".Equals(this.labPage.Text)?1: Convert.ToInt32(this.labPage.Text))) - 1;有可能是null 或""无法正确转型
this.labPage.Text = "1";
我在开始加载页面时候写了这么一句
在页面加载的时候控制还未生成!
this.labPage还未被实例化
好好调试看看this.labPage是什么状态。
我是在page_load里面调用方法,写了如下两句
如:contrlRepeater(userId);
this.labPage.Text = "1";
然后下面写了刚才发的方法加上按钮的事件
如下:
//Repeater分页控制显示方法
public void contrlRepeater(int userId)
{
string connectionString = ConfigurationManager.ConnectionStrings["db_health"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
string sql = "select * from health_user_followup_content where user_id=" + userId + "";
SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
DataSet ds = new DataSet();
sda.Fill(ds,"FollowContent");
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["FollowContent"].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 5;
pds.CurrentPageIndex =Convert.ToInt32(labPage.Text) - 1;
//pds.CurrentPageIndex = (this.labPage.Text == null ? 1 : ("".Equals(this.labPage.Text) ? 1 : Convert.ToInt32(this.labPage.Text))) - 1;
rpUserList.DataSource = pds;
LabCountPage.Text = pds.PageCount.ToString();
labPage.Text = (pds.CurrentPageIndex + 1).ToString();
this.lbtnpritPage.Enabled = true;
this.lbtnFirstPage.Enabled = true;
this.lbtnNextPage.Enabled = true;
this.lbtnDownPage.Enabled = true;
if (pds.CurrentPageIndex <= 1)
{
this.lbtnpritPage.Enabled = false;
this.lbtnFirstPage.Enabled = false;
}
if (pds.CurrentPageIndex == pds.PageCount - 1)
{
this.lbtnNextPage.Enabled = false;
this.lbtnDownPage.Enabled = false;
}
rpUserList.DataBind();
} protected void lbtnpritPage_Click(object sender, EventArgs e)
{
this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) - 1);
this.contrlRepeater(userId);
} protected void lbtnFirstPage_Click(object sender, EventArgs e)
{
this.labPage.Text = "1";
this.contrlRepeater(userId);
} protected void lbtnDownPage_Click(object sender, EventArgs e)
{
this.labPage.Text = this.LabCountPage.Text;
this.contrlRepeater(userId);
} protected void lbtnNextPage_Click(object sender, EventArgs e)
{
this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) + 1);
this.contrlRepeater(userId);
}
this.labPage.Text = "1";
改
this.labPage.Text = "1";
contrlRepeater(userId);
//this.labPage.Text = "1"; 确实意义已经不大了。
pds.CurrentPageIndex =(this.labPage.Text==null?1:("".Equals(this.labPage.Text)?1: Convert.ToInt32(this.labPage.Text))) - 1;
你有调试下这句话么.
编程要有严谨性.要不你以后编写代码会很吃力的。
pds.CurrentPageIndex =(this.labPage.Text==null?1:("".Equals(this.labPage.Text)?1: Convert.ToInt32(this.labPage.Text))) - 1;会报出刚才的错误
2.如果加上this.labPage.Text = "1";同事放在调用那个方法的前面
你给的那句就不会有错误,currentpageindex为0
如果去掉this.labPage.Text = "1";会报错
如果加上this.labPage.Text = "1";就直接运行通过,currentpageindex为0
//直接传页码 在第一次加载时 this.labPage.Text = "1";
public void contrlRepeater(int userId,int page)pds.CurrentPageIndex =page-1;
//有想法就自己写个分页控件, 封装所有分页属性。 在项目才能得共用复用。