repeater分页显示方法问题
//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 + "";
DataTable dt = new DataTable(sql,conn);
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dt.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();
}
在DataTable dt = new DataTable(sql,conn);这句中报出下面两个错误
//错误 2 与“System.Data.DataTable.DataTable(string, string)”最匹配的重载方法具有一些无效参数
//错误 3 参数“2”: 无法从“
System.Data.SqlClient.SqlConnection”转换为“string”
------解决方案--------------------你创建table,没有进行填充fill,
------解决方案--------------------DataTable第二个参数不是sql连接,而是连接字符串。