数据转换的一个疑问!
public partial class databind3 : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.databingtest();
this.Label2.Text = "1";
}
}
protected void databingtest()
{
string k = this.Label2.Text;
int curpage = Convert.ToInt32(k);
SqlConnection con = db.createconnection();
con.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from student", con);
DataSet ds = new DataSet();
sda.Fill(ds, "newstu");
System.Web.UI.WebControls.PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables["newstu"].DefaultView;
ps.AllowPaging = true;
ps.PageSize = 3;
ps.CurrentPageIndex = curpage - 1;
this.Button1.Visible=true;
this.Button2.Visible=true;
if (curpage == 1)
{
this.Button1.Visible = false;
}
if (curpage == ps.PageCount)
{
this.Button2.Visible = false;
}
this.Repeater1.DataSource = ps;
this.Repeater1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.Label2.Text = Convert.ToString(Convert.ToInt32(this.Label2.Text) - 1);
this.databingtest();
}
protected void Button2_Click(object sender, EventArgs e)
{
this.Label2.Text = Convert.ToString(Convert.ToInt32(this.Label2.Text) + 1);
this.databingtest();
}
发生错误的行:
int curpage = Convert.ToInt32(k)
错误提示:
确保方法的参数的格式正确。将一个字符串转换为datatime时,先分析该字符串以获取的日期,然后再将每个变量放置到datetime对象中
一点解释:
整个程序我没有用到任何datetime的数据转换.我试过用(int)this.label2.text这个方法,也将C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files目录的文件删除了,重新生成了项目
还是不行.....
不知道大家有什么看法没?或者是我的代码有问题!请指教! --------------------编程问答--------------------
补充:.NET技术 , ASP.NET