DropDownList分页,虽然我觉得问这个问题很离谱,但我无做出来!问问大家!!!
DataList里,使用DropDownList分页,DropDownList在DataList外面,我不要控件实现的,只要一个DropDownList,不要上一页、下一页、第一页、最后页这些,我只要一个DropDownList,绑定数据,进行分页,选择第一页,DataList显示第一页的数据,DropDownList显示第一页,如此类推,大家能给例子吗???EP ep = new EP();//实例化一个对象
protected void Page_Load(object sender, EventArgs e)
{
this.DownloadImgfillgv();
}
/// 用户自定义方法
public void DownloadImgfillgv()
{
SqlConnection scon = new SqlConnection(EP.GetConStr()); //调用Web.config连接数据库
scon.Open();//打开数据库连接
string SqlStr = "select * from Download order by time desc"; //数据库连接字符串
SqlDataAdapter da = new SqlDataAdapter(SqlStr, scon);
DataSet ds = new DataSet();
da.Fill(ds, "Download");
PagedDataSource objPage = new PagedDataSource();//创建分页类
objPage.DataSource = ds.Tables["Download"].DefaultView;//设置数据源
objPage.AllowPaging = true;
objPage.PageSize =4;
DlDownloadImg.DataSource = objPage;
DlDownloadImg.DataBind();
}
protected void DdlDownload_SelectedIndexChanged(object sender, EventArgs e)
{
}
DdlDownload_SelectedIndexChanged里添加什么代码实现上面的功能????????急急.... --------------------编程问答-------------------- 当然可以
获取数据的count,
然后你就根据pagecount算出总共多少页。
for循环添加到ddl --------------------编程问答--------------------
--------------------编程问答-------------------- 没有工具不能调试,行不行就不知道了,思路应该是正确的
int pagesize=4;//定义一个为每页大小的变量
int pageindex=1;//定义一个为索引页的变量
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) //判断页面是否是第一次加载
{
this.DownloadImgfillgv(pagesize,pageindex);
int count = getCount();
if(count%pagesize==0)
pageindex= count/pagesize
else
pageindex= count/pagesize + 1;
for(int i=1;i<=pageindex;i++)
DdlDownload.Items.add(i);//可不可以这样添加项?晕,在网吧什么工具都没有。。
}
}
public int getCount()//获取表中数据总条数
{
SqlConnection conn = new SqlConnection(ep.GetConStr);
conn.open();
string sql="select count(*) from Download";
SqlCommend cmd=new SqlCommend(sql,conn);
return convent.ToInt32(cmd.ExecuteScalar().ToString());
}
public void DownloadImgfillgv(int pagesize,int pageindex)
{
SqlConnection scon = new SqlConnection(EP.GetConStr()); //调用Web.config连接数据库
scon.Open();//打开数据库连接
string SqlStr = "select * from Download order by time desc"; //数据库连接字符串
//连接字符串改动,其实用存储过程最好,id是表的主键:
string sqlstr="select top "+ pagesize +"* from Download where id not exists (select top "+ pagesize*(pageindex-1) +" id from Download)"
SqlDataAdapter da = new SqlDataAdapter(SqlStr, scon);
DataSet ds = new DataSet();
da.Fill(ds, "Download");
PagedDataSource objPage = new PagedDataSource();//创建分页类
objPage.DataSource = ds.Tables["Download"].DefaultView;//设置数据源
//objPage.AllowPaging = true;
//objPage.PageSize =pagesize;
//DlDownloadImg.DataSource = objPage;
//DlDownloadImg.DataBind();
}
protected void DdlDownload_SelectedIndexChanged(object sender, EventArgs e)
{
this.DownloadImgfillgv(pagesize,Convten.ToInt32(this.DalDownload.SelectValue));
}
补充:.NET技术 , ASP.NET