求助不用DATAGRID分页的代码?? 我现在要显示数据库中的图片,每行要显示三个图片,万分感谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 PageSize = 10;sql="select * from products order by all_time desc ";if(!Page.IsPostBack){//计算总共有多少记录 RecordCount = CalculateRecord(); //计算总共有多少页//取整 PageCount = RecordCount/PageSize; if (RecordCount%PageSize > 0) PageCount = PageCount + 1; lblPageCount.Text = PageCount.ToString(); lblRecordCount.Text = RecordCount.ToString(); ViewState["PageCount"] = PageCount; CurrentPage = 0; ViewState["PageIndex"] = 0; //绑定 ListBind();}}public int CalculateRecord() { int intCount; string strCount = "select count(*) as co from products"; SqlConnection Con=new SqlConnection(data.constr);SqlCommand addCommand=new SqlCommand(strCount,Con);addCommand.Connection.Open();SqlDataReader dr;dr=addCommand.ExecuteReader();if(dr.Read()) { intCount = Int32.Parse(dr["co"].ToString()); } else { intCount = 0; } dr.Close(); return intCount; } ICollection CreateSource() { int StartIndex; //设定导入的起终地址 StartIndex = CurrentPage*PageSize; string strSel = "select * from products"; SqlConnection Con=new SqlConnection(data.constr);DataSet ds = new DataSet(); SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,Con); MyAdapter.Fill(ds,StartIndex,PageSize,"products"); return ds.Tables["products"].DefaultView; } public void ListBind() { dl1.DataSource = CreateSource(); dl1.DataBind(); lbnNextPage.Enabled = true; lbnPrevPage.Enabled = true; if(PageCount==0) { lblCurrentPage.Text = "0"; lbnNextPage.Enabled = false; lbnPrevPage.Enabled = false; } else { if(CurrentPage==(PageCount-1)) lbnNextPage.Enabled = false; if(CurrentPage==0) lbnPrevPage.Enabled = false; lblCurrentPage.Text = (CurrentPage+1).ToString(); } } public void Page_OnClick(Object sender,CommandEventArgs e) { CurrentPage = (int)ViewState["PageIndex"]; PageCount = (int)ViewState["PageCount"]; string cmd = e.CommandName; //判断cmd,以判定翻页方向 switch(cmd) { case "next": if(CurrentPage<(PageCount-1)) CurrentPage++; break; case "prev": if(CurrentPage>0) CurrentPage--; break;case "first":CurrentPage=0;break;case "last":CurrentPage=PageCount-1;break;} ViewState["PageIndex"] = CurrentPage; ListBind(); } HTML 部分:<TABLE id="Table2" cellSpacing="1" cellPadding="1" width="540" border="0"><TR><TD align="right">共<asp:label id="lblRecordCount" runat="server">Label</asp:label>条记录 共<asp:label id="lblPageCount" runat="server">Label</asp:label>页 当前第<asp:label id="lblCurrentPage" runat="server">Label</asp:label>页 <asp:linkbutton id="lbnFirstPage" runat="server" CommandName="first" OnCommand="Page_OnClick">首页</asp:linkbutton> <asp:linkbutton id="lbnPrevPage" CommandName="prev" OnCommand="Page_OnClick" Runat="server">上一页</asp:linkbutton> <asp:linkbutton id="lbnNextPage" runat="server" CommandName="next" OnCommand="Page_OnClick">下一页</asp:linkbutton> <asp:linkbutton id="lbnLastPage" runat="server" CommandName="last" OnCommand="Page_OnClick">尾页</asp:linkbutton></TD></TR></TABLE> up---------------------------------------------------------------------------------------------腰缠70元到月入近10万http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=453IT工程师 毕业4年我年薪涨到30万 http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=51126岁青年坐拥千万域名资产 从小玩家变成CEO http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=515程序员的酸甜苦辣:告别Coding http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=341从月薪3500到700万(一)http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=170网络草根月赚3000的十种方法http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=517如果我是女的 我肯定不会嫁给做网站的http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=512 两个Iframe之间传值 asp.net中突然就不能改变控件的ID了 NeatUpload上传组件的问题 求一算法? 怎么样实现我的网页里的广告点击的次数? Repeater控件的ItemCommand怎么不能用了?谢谢。 混乱了,大侠带我出迷宫! 上传文件出错,请指教,谢谢!!! 關于"關閉對話框"的問題! 一个邪门的问题! 网站通行证技术如何实现 关于微软TabStrip的用法?
sql="select * from products order by all_time desc ";
if(!Page.IsPostBack)
{
//计算总共有多少记录
RecordCount = CalculateRecord();
//计算总共有多少页
//取整
PageCount = RecordCount/PageSize;
if (RecordCount%PageSize > 0)
PageCount = PageCount + 1;
lblPageCount.Text = PageCount.ToString();
lblRecordCount.Text = RecordCount.ToString();
ViewState["PageCount"] = PageCount;
CurrentPage = 0;
ViewState["PageIndex"] = 0;
//绑定
ListBind();}
}
public int CalculateRecord()
{
int intCount;
string strCount = "select count(*) as co from products";
SqlConnection Con=new SqlConnection(data.constr);
SqlCommand addCommand=new SqlCommand(strCount,Con);
addCommand.Connection.Open();
SqlDataReader dr;
dr=addCommand.ExecuteReader();
if(dr.Read())
{
intCount = Int32.Parse(dr["co"].ToString());
}
else
{
intCount = 0;
}
dr.Close();
return intCount;
} ICollection CreateSource()
{ int StartIndex;
//设定导入的起终地址
StartIndex = CurrentPage*PageSize;
string strSel = "select * from products";
SqlConnection Con=new SqlConnection(data.constr);
DataSet ds = new DataSet();
SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,Con);
MyAdapter.Fill(ds,StartIndex,PageSize,"products");
return ds.Tables["products"].DefaultView;
}
public void ListBind()
{
dl1.DataSource = CreateSource();
dl1.DataBind();
lbnNextPage.Enabled = true;
lbnPrevPage.Enabled = true;
if(PageCount==0)
{
lblCurrentPage.Text = "0";
lbnNextPage.Enabled = false;
lbnPrevPage.Enabled = false;
}
else
{
if(CurrentPage==(PageCount-1)) lbnNextPage.Enabled = false;
if(CurrentPage==0) lbnPrevPage.Enabled = false;
lblCurrentPage.Text = (CurrentPage+1).ToString();
}
}
public void Page_OnClick(Object sender,CommandEventArgs e)
{
CurrentPage = (int)ViewState["PageIndex"];
PageCount = (int)ViewState["PageCount"];
string cmd = e.CommandName;
//判断cmd,以判定翻页方向
switch(cmd)
{
case "next":
if(CurrentPage<(PageCount-1)) CurrentPage++;
break;
case "prev":
if(CurrentPage>0) CurrentPage--;
break;
case "first":
CurrentPage=0;
break;
case "last":
CurrentPage=PageCount-1;
break;
} ViewState["PageIndex"] = CurrentPage; ListBind(); }
HTML 部分:<TABLE id="Table2" cellSpacing="1" cellPadding="1" width="540" border="0">
<TR>
<TD align="right">共<asp:label id="lblRecordCount" runat="server">Label</asp:label>条记录
共<asp:label id="lblPageCount" runat="server">Label</asp:label>页 当前第<asp:label id="lblCurrentPage" runat="server">Label</asp:label>页
<asp:linkbutton id="lbnFirstPage" runat="server" CommandName="first" OnCommand="Page_OnClick">首页</asp:linkbutton>
<asp:linkbutton id="lbnPrevPage" CommandName="prev" OnCommand="Page_OnClick" Runat="server">上一页</asp:linkbutton>
<asp:linkbutton id="lbnNextPage" runat="server" CommandName="next" OnCommand="Page_OnClick">下一页</asp:linkbutton>
<asp:linkbutton id="lbnLastPage" runat="server" CommandName="last" OnCommand="Page_OnClick">尾页</asp:linkbutton></TD>
</TR>
</TABLE>
腰缠70元到月入近10万
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=453IT工程师 毕业4年我年薪涨到30万
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=51126岁青年坐拥千万域名资产 从小玩家变成CEO
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=515程序员的酸甜苦辣:告别Coding
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=341从月薪3500到700万(一)
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=170网络草根月赚3000的十种方法
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=517如果我是女的 我肯定不会嫁给做网站的
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=512