ASP.NET中,想一行显示四个图片,用何好方法?
ASP.NET中,用DataTable取出来了若干条记录,而想一行显示四条记录信息(也可理解为一行显示四个图片信息),然后换行,分页,有何好方法???或者用什么控件方便?...
ASP.NET中,用DataTable 取出来了若干条记录,而想一行显示四条记录信息(也可理解为一行显示四个图片信息),然后换行,分页,有何好方法???或者用什么控件方便???
怎么没有人知道吗 ?急啊,分也送不出去 展开
怎么没有人知道吗 ?急啊,分也送不出去 展开
展开全部
用datalist
我写的一个分页的程序给你
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using jclj.DbBase;
using System.Data.SqlClient;
using System.Text;
namespace jclj.fy
{
public class fyclass : BaseDb
{
#region //声明字段:
private Panel Pager;
private HyperLink FirstPage;
private HyperLink PrevPage;
private HyperLink NextPage;
private HyperLink LastPage;
private Literal RecordCount;
private Literal PageCount;
private Literal Pageindex;
private Literal CurIndex;
#endregion
#region 构造函数:
public fyclass()
{
Pager = new Panel();
FirstPage = new HyperLink();
PrevPage = new HyperLink();
NextPage = new HyperLink();
LastPage = new HyperLink();
FirstPage.Text = " 首页 ";
PrevPage.Text = " 上一页 ";
NextPage.Text = " 下一页 ";
LastPage.Text = " 尾页 ";
RecordCount = new Literal();
PageCount = new Literal();
Pageindex = new Literal();
CurIndex = new Literal();
}
#endregion
#region 分页控件的导航部件:
public void InstantiateIn(Control control)
{
Table table = new Table();
table.BorderWidth = Unit.Pixel(0);
table.CellSpacing = 2;
table.CellPadding = 0;
TableRow row = new TableRow();
row.VerticalAlign = VerticalAlign.Top;
table.Rows.Add(row);
TableCell cell = new TableCell();
cell.HorizontalAlign = HorizontalAlign.Right;
cell.VerticalAlign = VerticalAlign.Middle;
cell.Width = 300;
cell.Controls.Add(RecordCount);
cell.Controls.Add(PageCount);
cell.Controls.Add(Pageindex);
row.Cells.Add(cell);
cell = new TableCell();
cell.HorizontalAlign = HorizontalAlign.Center;
cell.Controls.Add(Pager);
row.Cells.Add(cell);
cell = new TableCell();
cell.VerticalAlign = VerticalAlign.Middle;
cell.Width = 90;
cell.Controls.Add(FirstPage);
cell.Controls.Add(PrevPage);
row.Cells.Add(cell);
cell = new TableCell();
cell.Width = 90;
cell.VerticalAlign = VerticalAlign.Middle;
cell.Controls.Add(NextPage);
cell.Controls.Add(LastPage);
row.Cells.Add(cell);
cell = new TableCell();
cell.VerticalAlign = VerticalAlign.Middle;
cell.Width = 90;
cell.Controls.Add(CurIndex);
row.Cells.Add(cell);
control.Controls.Add(table);
}
#endregion
public void NewsBind(string sql, string pageID, int pageCount, string pageUrl, DataList contectID)//repeater分页并绑定
{
string strConn = ConfigurationManager.ConnectionStrings["jc!ljConnectionString2"].ToString();
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlDataAdapter Adapter = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
try
{
Adapter.Fill(ds, "table");
PagedDataSource objPage = new PagedDataSource();
objPage.DataSource = ds.Tables["table"].DefaultView;
objPage.AllowPaging = true;
objPage.PageSize = pageCount;
int CurPage;
if (pageID != null)
{
CurPage = Convert.ToInt32(pageID);
}
else
{
CurPage = 1;
}
objPage.CurrentPageIndex = CurPage - 1;
contectID.DataSource = objPage;//这里更改控件名称
contectID.DataBind();//这里更改控件名称
RecordCount.Text = "共有" + objPage.DataSourceCount.ToString() + "条 ";
PageCount.Text = "共有" + objPage.PageCount.ToString() + "页 ";
Pageindex.Text = "当前第" + CurPage.ToString() + "页 ";
CurIndex.Text = PageList(objPage.PageCount, CurPage, pageUrl);
FirstPage.NavigateUrl = pageUrl + "page=1";
PrevPage.NavigateUrl = pageUrl + "page=" + (CurPage - 1);
NextPage.NavigateUrl = pageUrl + "page=" + (CurPage + 1);
LastPage.NavigateUrl = pageUrl + "page=" + objPage.PageCount.ToString();
if (CurPage <= 1 && objPage.PageCount <= 1)
{
FirstPage.NavigateUrl = "";
PrevPage.NavigateUrl = "";
NextPage.NavigateUrl = "";
LastPage.NavigateUrl = "";
}
if (CurPage <= 1 && objPage.PageCount > 1)
{
FirstPage.NavigateUrl = "";
PrevPage.NavigateUrl = "";
}
if (CurPage >= objPage.PageCount)
{
NextPage.NavigateUrl = "";
LastPage.NavigateUrl = "";
}
}
catch (Exception error)
{
throw new Exception(error.Message ) ;
}
finally
{
conn.Close();
}
}
public string PageList(int Pagecount, int Pageindex, string PageUrl)
{
StringBuilder sb = new StringBuilder();
sb.Append("<select id=\"Page_Jump\" name=\"Page_Jump\" onchange=\"window.location='" + PageUrl + "page='+ this.options[this.selectedIndex].value + '';\">");
for (int i = 1; i <= Pagecount; i++)
{
if (Pageindex == i)
sb.Append("<option value='" + i + "' selected>" + i + "</option>");
else
sb.Append("<option value='" + i + "'>" + i + "</option>");
}
sb.Append("</select>");
return sb.ToString();
}
}
}
调用的时候 只要在页面中拉一个datalist 和一个label 设置datalist的
RepeatDirection="horizontal" RepeatColumns="4"
然后在page_load 事件中加入
string strSql=“查询语句”;
jclj.fy.fyclass fy = new jclj.fy.fyclass();
fy.InstantiateIn(label的id);
string url = "调用页.aspx?";//问号一定不能少
fy.NewsBind(strSql, Request.QueryString["page"], 20, url, datalist控件的id);
完全搞定
我写的一个分页的程序给你
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using jclj.DbBase;
using System.Data.SqlClient;
using System.Text;
namespace jclj.fy
{
public class fyclass : BaseDb
{
#region //声明字段:
private Panel Pager;
private HyperLink FirstPage;
private HyperLink PrevPage;
private HyperLink NextPage;
private HyperLink LastPage;
private Literal RecordCount;
private Literal PageCount;
private Literal Pageindex;
private Literal CurIndex;
#endregion
#region 构造函数:
public fyclass()
{
Pager = new Panel();
FirstPage = new HyperLink();
PrevPage = new HyperLink();
NextPage = new HyperLink();
LastPage = new HyperLink();
FirstPage.Text = " 首页 ";
PrevPage.Text = " 上一页 ";
NextPage.Text = " 下一页 ";
LastPage.Text = " 尾页 ";
RecordCount = new Literal();
PageCount = new Literal();
Pageindex = new Literal();
CurIndex = new Literal();
}
#endregion
#region 分页控件的导航部件:
public void InstantiateIn(Control control)
{
Table table = new Table();
table.BorderWidth = Unit.Pixel(0);
table.CellSpacing = 2;
table.CellPadding = 0;
TableRow row = new TableRow();
row.VerticalAlign = VerticalAlign.Top;
table.Rows.Add(row);
TableCell cell = new TableCell();
cell.HorizontalAlign = HorizontalAlign.Right;
cell.VerticalAlign = VerticalAlign.Middle;
cell.Width = 300;
cell.Controls.Add(RecordCount);
cell.Controls.Add(PageCount);
cell.Controls.Add(Pageindex);
row.Cells.Add(cell);
cell = new TableCell();
cell.HorizontalAlign = HorizontalAlign.Center;
cell.Controls.Add(Pager);
row.Cells.Add(cell);
cell = new TableCell();
cell.VerticalAlign = VerticalAlign.Middle;
cell.Width = 90;
cell.Controls.Add(FirstPage);
cell.Controls.Add(PrevPage);
row.Cells.Add(cell);
cell = new TableCell();
cell.Width = 90;
cell.VerticalAlign = VerticalAlign.Middle;
cell.Controls.Add(NextPage);
cell.Controls.Add(LastPage);
row.Cells.Add(cell);
cell = new TableCell();
cell.VerticalAlign = VerticalAlign.Middle;
cell.Width = 90;
cell.Controls.Add(CurIndex);
row.Cells.Add(cell);
control.Controls.Add(table);
}
#endregion
public void NewsBind(string sql, string pageID, int pageCount, string pageUrl, DataList contectID)//repeater分页并绑定
{
string strConn = ConfigurationManager.ConnectionStrings["jc!ljConnectionString2"].ToString();
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlDataAdapter Adapter = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
try
{
Adapter.Fill(ds, "table");
PagedDataSource objPage = new PagedDataSource();
objPage.DataSource = ds.Tables["table"].DefaultView;
objPage.AllowPaging = true;
objPage.PageSize = pageCount;
int CurPage;
if (pageID != null)
{
CurPage = Convert.ToInt32(pageID);
}
else
{
CurPage = 1;
}
objPage.CurrentPageIndex = CurPage - 1;
contectID.DataSource = objPage;//这里更改控件名称
contectID.DataBind();//这里更改控件名称
RecordCount.Text = "共有" + objPage.DataSourceCount.ToString() + "条 ";
PageCount.Text = "共有" + objPage.PageCount.ToString() + "页 ";
Pageindex.Text = "当前第" + CurPage.ToString() + "页 ";
CurIndex.Text = PageList(objPage.PageCount, CurPage, pageUrl);
FirstPage.NavigateUrl = pageUrl + "page=1";
PrevPage.NavigateUrl = pageUrl + "page=" + (CurPage - 1);
NextPage.NavigateUrl = pageUrl + "page=" + (CurPage + 1);
LastPage.NavigateUrl = pageUrl + "page=" + objPage.PageCount.ToString();
if (CurPage <= 1 && objPage.PageCount <= 1)
{
FirstPage.NavigateUrl = "";
PrevPage.NavigateUrl = "";
NextPage.NavigateUrl = "";
LastPage.NavigateUrl = "";
}
if (CurPage <= 1 && objPage.PageCount > 1)
{
FirstPage.NavigateUrl = "";
PrevPage.NavigateUrl = "";
}
if (CurPage >= objPage.PageCount)
{
NextPage.NavigateUrl = "";
LastPage.NavigateUrl = "";
}
}
catch (Exception error)
{
throw new Exception(error.Message ) ;
}
finally
{
conn.Close();
}
}
public string PageList(int Pagecount, int Pageindex, string PageUrl)
{
StringBuilder sb = new StringBuilder();
sb.Append("<select id=\"Page_Jump\" name=\"Page_Jump\" onchange=\"window.location='" + PageUrl + "page='+ this.options[this.selectedIndex].value + '';\">");
for (int i = 1; i <= Pagecount; i++)
{
if (Pageindex == i)
sb.Append("<option value='" + i + "' selected>" + i + "</option>");
else
sb.Append("<option value='" + i + "'>" + i + "</option>");
}
sb.Append("</select>");
return sb.ToString();
}
}
}
调用的时候 只要在页面中拉一个datalist 和一个label 设置datalist的
RepeatDirection="horizontal" RepeatColumns="4"
然后在page_load 事件中加入
string strSql=“查询语句”;
jclj.fy.fyclass fy = new jclj.fy.fyclass();
fy.InstantiateIn(label的id);
string url = "调用页.aspx?";//问号一定不能少
fy.NewsBind(strSql, Request.QueryString["page"], 20, url, datalist控件的id);
完全搞定
展开全部
现在可以用数据控件绑定,也可以用TABLE显示都可以的
要是控件绑定的话 设置好就可以了 用DataList或者Repeater控件容易控制显示的方式
要是想用Table可以参考这个方法:
动态创建Table的方法
http://bbs.92jp.com/bbs/ShowPost.Asp?ID=1204
要是控件绑定的话 设置好就可以了 用DataList或者Repeater控件容易控制显示的方式
要是想用Table可以参考这个方法:
动态创建Table的方法
http://bbs.92jp.com/bbs/ShowPost.Asp?ID=1204
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以用DATALIST
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询