日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

自定义repeater带分页功能的DataGrid(仿PetShop)

發布時間:2023/12/18 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 自定义repeater带分页功能的DataGrid(仿PetShop) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第一步:新建控件庫

代碼 using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;

namespace CustomServerControlsLib
{
public class CustomGrid : Repeater
{
//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}>&#060;&nbsp;上一頁</a>";
private const string LINK_MORE = "<a href=?page={0}>下一頁&nbsp;&#062;</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);
}
}
}

?

第二步:新建用戶控件

?

前臺 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CarGridControl.ascx.cs" Inherits="分頁實踐.CarGridControl" %>
<%@ Register TagPrefix="CC" Namespace="CustomServerControlsLib" Assembly="CustomServerControlsLib" %>
<CC:CustomGrid ID="CarGrid" runat="server" EmptyText="暫時沒有記錄" PageSize="10" EnableViewState="false"
OnPageIndexChanged
="PageChanged" onload="CarGrid_Load">
<HeaderTemplate>
<table cellspacing="0" cellpadding="0" border="0" width="387">
</HeaderTemplate>
<ItemTemplate>
<tr><td><table> <tr align="left" valign="top">
<td width="100"><%# Eval("logo") %></td>
<td width="100"><%# Eval("price", "{0:c}") %></td>
</tr> </table></td></tr>


</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</CC:CustomGrid>

?

后臺 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using 分頁實踐.Model;
using System.Data.SqlClient;

namespace 分頁實踐
{
public partial class CarGridControl : System.Web.UI.UserControl
{
public void PageChanged(object sender, DataGridPageChangedEventArgs e)
{
CarGrid.CurrentPageIndex = e.NewPageIndex;
IList
<ItemInfo> carlist = new List<ItemInfo>();

using( SqlDataReader dr = SqlHelper.ExecuteReader(
SqlHelper.ConnectionStringLocalTransaction
, System.Data.CommandType.Text
, "select logo, price from car"
, null ) )
{


while (dr.Read()){
ItemInfo item = new ItemInfo(dr.GetString(0), dr.GetDecimal(1));
carlist.Add(item);
}
}
CarGrid.DataSource = carlist;
CarGrid.DataBind();

}

protected void CarGrid_Load(object sender, EventArgs e)
{



}

}
}

?

一個Model

?

代碼 using System;

namespace 分頁實踐.Model
{
///
<summary>
/// Business entity used to model an item.
///
</summary>
[Serializable]
public class ItemInfo
{

// Internal member variables
private string logo;
private decimal price;

public ItemInfo() { }
public ItemInfo(string logo, decimal price)
{
this.logo = logo;
this.price = price;
}

// Properties

public string Logo
{
get { return logo; }
}



public decimal Price
{
get { return price; }
}




}
}

?

第三步:表示層使用用戶控件

?

表示層使用用戶控件 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="分頁實踐.WebForm1" %>
<%@ Register src="~/Controls/CarGridControl.ascx" tagname="CarGridControl" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>


<uc1:CarGridControl ID="CarGridControl1" runat="server" />


</div>
</form>
</body>
</html>

?

轉載于:https://www.cnblogs.com/qhnokia/archive/2010/01/10/1643660.html

總結

以上是生活随笔為你收集整理的自定义repeater带分页功能的DataGrid(仿PetShop)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产在线观看免费高清 | 亚洲av片不卡无码久久 | 六月婷婷网 | 在线艹 | 成人做爰视频www网站小优视频 | 懂色中文一区二区在线播放 | 黄色在线观看网址 | 人妻久久久一区二区三区 | 四虎黄色网 | 大乳女喂男人吃奶视频 | 久久国产高清 | 男人天堂网在线观看 | 亚洲三级精品 | 中文天堂网 | 在线免费成人 | 少妇av网 | 狠狠爱欧美 | 亚洲免费专区 | 97在线视频免费 | 久久久久亚洲色欲AV无码网站 | 国产精品手机在线观看 | 97国产成人无码精品久久久 | 久久久久久久久久一区二区 | japanesehdxxxx | 久久2019| 国产一二三区在线视频 | 久久日韩| 天天做天天爱天天爽综合网 | 91久久精品国产91性色tv | 日韩欧美在线视频观看 | 国产精品va在线 | 91国产网站| 国产成人在线观看免费 | 国产v亚洲v天堂无码 | 五月天天 | 亚洲3p| 激情视频在线播放 | 福利网址在线 | 女优在线观看 | 亚洲视频免费播放 | 久久精品一 | 在线色av| 综合久久五月 | 狠狠干超碰 | 国产精品乱码一区二区三区 | 精品综合网 | 色中文字幕在线观看 | 黄色一级片久久 | 久在线观看视频 | 青青青在线视频 | 国产露脸91国语对白 | www.天天操| 国产无限制自拍 | 欧美一区二区三区视频 | 精品国产一区三区 | 色性网| 日本精品久久久久久久 | 五十路六十路七十路熟婆 | 国产麻豆一区二区三区在线观看 | 怡红院男人的天堂 | 欧美精品久久久 | aaa一级片 | 亚洲福利视频在线 | 美味的客房沙龙服务 | 91成年人网站 | hd极品free性xxx护士 | 三级黄色小视频 | 97视频免费看 | 99爱在线视频 | 福利片在线观看 | 操操操网 | 成人午夜视频在线观看 | 天天视频色 | 成人在线小视频 | 久久久免费毛片 | 男人天堂2019| 日韩美av| 超碰牛牛 | 免费在线观看a视频 | 国产女同在线观看 | 一本色道久久综合亚洲精品小说 | 亚洲AV无码一区二区三区性 | 日韩中文字幕在线免费观看 | 亚洲看片网 | 糖心av| 香蕉网址| 强伦人妻一区二区三区 | 69精品人妻一区二区三区 | 网站免费黄色 | 国产精品视频自拍 | 男人的天堂网在线 | 国产伊人网 | 在线免费观看黄色av | 日本久久中文字幕 | 中年夫妇啪啪高潮 | 久久妇女 | 国产白丝一区二区三区 | 在线观看亚洲色图 | 欧美成人一区二区在线 |