自己写个 控件 继承自 DataList 然后 使用 DataGrid 或者GridView 的翻页事件就好了 public class CustomList : DataList { //Static constants protected const string HTML1 = "<table cellpadding=0 cellspacing=0><tr><td colspan=2>"; protected const string HTML2 = "</td></tr><tr><td class=paging align=left>"; protected const string HTML3 = "</td><td align=right class=paging>"; protected const string HTML4 = "</td></tr></table>"; private static readonly Regex RX = new Regex(@"^&page=\d+", RegexOptions.Compiled); private const string LINK_PREV = "<a href=?page={0}>< Previous</a>"; private const string LINK_MORE = "<a href=?page={0}>More ></a>"; private const string KEY_PAGE = "page"; private const string COMMA = "?"; private const string AMP = "&"; protected string emptyText; private IList dataSource; private int pageSize = 10; private int currentPageIndex; private int itemCount; override public object DataSource { set { //This try catch block is to avoid issues with the VS.NET designer //The designer will try and bind a datasource which does not derive from ILIST try { dataSource = (IList)value; ItemCount = dataSource.Count; } catch { dataSource = null; ItemCount = 0; } } } public int PageSize { get { return pageSize; } set { pageSize = value; } } protected int PageCount { get { return (ItemCount - 1) / pageSize; } } virtual protected int ItemCount { get { return itemCount; } set { itemCount = value; } } virtual public int CurrentPageIndex { get { return currentPageIndex; } set { currentPageIndex = value; } } public string EmptyText { set { emptyText = value; } } public void SetPage(int index) { OnPageIndexChanged(new DataGridPageChangedEventArgs(null, index)); } override protected void OnLoad(EventArgs e) { if (Visible) { string page = Context.Request[KEY_PAGE]; int index = (page != null) ? int.Parse(page) : 0; SetPage(index); } } /// <summary> /// Overriden method to control how the page is rendered /// </summary> /// <param name="writer"></param> override protected void Render(HtmlTextWriter writer) { //Check there is some data attached if (ItemCount == 0) { writer.Write(emptyText); return; } //Mask the query string query = Context.Request.Url.Query.Replace(COMMA, AMP); query = RX.Replace(query, string.Empty); // Write out the first part of the control, the table header writer.Write(HTML1); // Call the inherited method base.Render(writer);
// Write out a table row closure writer.Write(HTML2); //Determin whether next and previous buttons are required //Previous button? if (currentPageIndex > 0) writer.Write(string.Format(LINK_PREV, (currentPageIndex - 1) + query)); //Close the table data tag writer.Write(HTML3); //Next button? if (currentPageIndex < PageCount) writer.Write(string.Format(LINK_MORE, (currentPageIndex + 1) + query)); //Close the table writer.Write(HTML4); } override protected void OnDataBinding(EventArgs e) { //Work out which items we want to render to the page int start = CurrentPageIndex * pageSize; int size = Math.Min(pageSize, ItemCount - start); IList page = new ArrayList(); //Add the relevant items from the datasource for (int i = 0; i < size; i++) page.Add(dataSource[start + i]); //set the base objects datasource base.DataSource = page; base.OnDataBinding(e); } public event DataGridPageChangedEventHandler PageIndexChanged; virtual protected void OnPageIndexChanged(DataGridPageChangedEventArgs e) { if (PageIndexChanged != null) PageIndexChanged(this, e); } }
if(数据行)
{
if(e.item.itemindex % X ==0)
{
e.item.value = e.item.value +“<BR>"+下划线的html表达字符串;
}
}
加下划线这个可以
实现分页的话最好用存储过程来分页,就是根据页数传参直接查出第X页的数据
如果数据量不打的话用PagedDataSource也行
public void Page_Load(Object src,EventArgs e)
{
OleDbConnection objConn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\test.mdb");
OleDbDataAdapter objCommand=new OleDbDataAdapter("select * from Users",objConn);
DataSet ds=new DataSet();
objCommand.Fill(ds); //对PagedDataSource 对象的相关属性赋值
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ds.Tables[0].DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 5;
int CurPage; //当前页面从Page查询参数获取
if (Request.QueryString["Page"] != null)
CurPage=Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage=1; objPds.CurrentPageIndex = CurPage-1;
lblCurrentPage.Text = "Page: " + CurPage.ToString(); if (!objPds.IsFirstPage)
lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage-1); if (!objPds.IsLastPage)
lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage+1); //把PagedDataSource 对象赋给Repeater控件
DataList1.DataSource=objPds;
DataList1.DataBind();
}
window.onload=function()
{ var rptable= document.body.getElementsByTagName("hr");//必须是document.body
for(var i=4;i<20;i+=5)
{
rptable[i].style.display="block"; //item()也行
rptable[i].style.color="red";
rptable[i].style.size="10px"; //setProperty("size","10px","")在ie6中行不通
}
} <asp:Repeater ID="rptb" runat="server">
<HeaderTemplate>
<table id="tb" width="100%">
<tr>
<th width=20>序号</th><th width=200>公司名称 </th><th width=200>联系人 </th><th width=200>地址 </th>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table width="100%">
<tr >
<td width=20><%#Eval("序号").ToString().Length > 15 ? Eval("序号").ToString().Remove(15) + "......" : Eval("序号")%></td>
<td width=200><%#Eval("topicid")%></td>
<td width=200><%#Eval("topictitle").ToString().Length >15 ? Eval("topictitle").ToString().Remove(15) + "......" : Eval("topictitle")%></td>
<td width=200><%#Eval("topiccontent").ToString().Length >15 ? Eval("topiccontent").ToString().Remove(15) + "......" : Eval("topiccontent")%></td>
</tr>
</table>
<hr / style="display:none">
</ItemTemplate>
</asp:Repeater>
然后 使用 DataGrid 或者GridView 的翻页事件就好了
public class CustomList : DataList {
//Static constants
protected const string HTML1 = "<table cellpadding=0 cellspacing=0><tr><td colspan=2>";
protected const string HTML2 = "</td></tr><tr><td class=paging align=left>";
protected const string HTML3 = "</td><td align=right class=paging>";
protected const string HTML4 = "</td></tr></table>";
private static readonly Regex RX = new Regex(@"^&page=\d+", RegexOptions.Compiled);
private const string LINK_PREV = "<a href=?page={0}>< Previous</a>";
private const string LINK_MORE = "<a href=?page={0}>More ></a>";
private const string KEY_PAGE = "page";
private const string COMMA = "?";
private const string AMP = "&"; protected string emptyText;
private IList dataSource;
private int pageSize = 10;
private int currentPageIndex;
private int itemCount; override public object DataSource {
set {
//This try catch block is to avoid issues with the VS.NET designer
//The designer will try and bind a datasource which does not derive from ILIST
try {
dataSource = (IList)value;
ItemCount = dataSource.Count;
}
catch {
dataSource = null;
ItemCount = 0;
}
}
} public int PageSize {
get { return pageSize; }
set { pageSize = value; }
} protected int PageCount {
get { return (ItemCount - 1) / pageSize; }
} virtual protected int ItemCount {
get { return itemCount; }
set { itemCount = value; }
} virtual public int CurrentPageIndex {
get { return currentPageIndex; }
set { currentPageIndex = value; }
} public string EmptyText {
set { emptyText = value; }
} public void SetPage(int index) {
OnPageIndexChanged(new DataGridPageChangedEventArgs(null, index));
} override protected void OnLoad(EventArgs e) {
if (Visible) {
string page = Context.Request[KEY_PAGE];
int index = (page != null) ? int.Parse(page) : 0;
SetPage(index);
}
}
/// <summary>
/// Overriden method to control how the page is rendered
/// </summary>
/// <param name="writer"></param>
override protected void Render(HtmlTextWriter writer) { //Check there is some data attached
if (ItemCount == 0) {
writer.Write(emptyText);
return;
} //Mask the query
string query = Context.Request.Url.Query.Replace(COMMA, AMP);
query = RX.Replace(query, string.Empty);
// Write out the first part of the control, the table header
writer.Write(HTML1); // Call the inherited method
base.Render(writer);
// Write out a table row closure
writer.Write(HTML2); //Determin whether next and previous buttons are required
//Previous button?
if (currentPageIndex > 0)
writer.Write(string.Format(LINK_PREV, (currentPageIndex - 1) + query)); //Close the table data tag
writer.Write(HTML3); //Next button?
if (currentPageIndex < PageCount)
writer.Write(string.Format(LINK_MORE, (currentPageIndex + 1) + query)); //Close the table
writer.Write(HTML4);
} override protected void OnDataBinding(EventArgs e) { //Work out which items we want to render to the page
int start = CurrentPageIndex * pageSize;
int size = Math.Min(pageSize, ItemCount - start); IList page = new ArrayList(); //Add the relevant items from the datasource
for (int i = 0; i < size; i++)
page.Add(dataSource[start + i]); //set the base objects datasource
base.DataSource = page;
base.OnDataBinding(e); } public event DataGridPageChangedEventHandler PageIndexChanged; virtual protected void OnPageIndexChanged(DataGridPageChangedEventArgs e) {
if (PageIndexChanged != null)
PageIndexChanged(this, e);
}
}
这代码是repeater控件的,你确定,而且我说过了这只是用javascript实现下划线的,至于要分页我建议你用AspNetPage控件。如果你要有datalist二楼的方法好像也可以,要分页你还得想办法