最近开发的几个 比较不错的控件 ~大家指点下

bhtfg538 2008-11-04 09:37:44
加精
RT, (顺便散散分~)
不说多了
代码下

这是 数据控件的代码: 适合IList 泛型的
YsmvRepeater.cs

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

namespace YSMV.Control
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:YsmvRepeater runat=\"server\" AllowPage=\"true\" PageSize=\"10\" ShowPage=\"true\"></{0}:YsmvRepeater>")]
public class YsmvRepeater : Repeater
{

//Static param
private static readonly Regex RX;
private static readonly object EventPageChanged;

static YsmvRepeater()
{
RX = new Regex(@"^&page=\d+", RegexOptions.Compiled);
EventPageChanged = new object();
}

//Static constants
protected const string HTML1 = "<table cellpadding=0 cellspacing=0 class='inputTable'><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 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;
private bool allowPage = false;
private bool showPage = true;

[Browsable(true)
, Category("Appearance"),
DefaultValue(true),
Description("是否显示翻页链接")
]
public bool ShowPage
{
get { return showPage; }
set { showPage = value; }
}
[Browsable(true),
Category("Appearance"),
DefaultValue(true),
Description("是否允许分页")]
public bool AllowPage
{
get { return allowPage; }
set { allowPage = value; }
}
[Browsable(true),
Category("Appearance"),
DefaultValue(10),
Description("每页显示的数量")
]
public int PageSize
{
get { return pageSize; }
set { pageSize = value; }
}
[Browsable(true),
Category("Appearance"),
DefaultValue(""),
Description("无记录时候显示的内容")]
public string EmptyText
{
set { emptyText = value; }
}
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;
}
}
}
protected int PageCount
{
get { return (ItemCount - 1) / pageSize; }
}

virtual public int ItemCount
{
get { return itemCount; }
set
{itemCount = value;}
}

virtual public int CurrentPageIndex
{
get { return currentPageIndex; }
set { currentPageIndex = value; }
}

public void SetPage(int index)
{
//OnPageIndexChanged(new DataGridPageChangedEventArgs(null, index));
OnPageIndexChanged(new GridViewPageEventArgs(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
string page = Context.Request[KEY_PAGE];
int index = (page != null) ? int.Parse(page) : 0;
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)
{
if (ShowPage)
writer.Write(string.Format(LINK_PREV, (currentPageIndex - 1) + query));
}

//Close the table data tag
writer.Write(HTML3);

//Next button?
if (currentPageIndex < PageCount)
{
if (ShowPage)
writer.Write(string.Format(LINK_MORE, (currentPageIndex + 1) + query));
}

//Close the table
writer.Write(HTML4);
}

override protected void OnDataBinding(EventArgs e)
{
if (!allowPage)
{
base.DataSource = dataSource;
base.OnDataBinding(e);
return;
}
//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;
public event GridViewPageEventHandler PageIndexChanged
{
add
{
Events.AddHandler(EventPageChanged, value);
}
remove
{
Events.RemoveHandler(EventPageChanged, value);
}
}
virtual protected void OnPageIndexChanged(GridViewPageEventArgs e)
{
GridViewPageEventHandler pagehandler = (GridViewPageEventHandler)Events[EventPageChanged];
if (pagehandler != null)
pagehandler(this, e);
}
}
}


...全文
3058 241 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
241 条回复
切换为时间正序
请发表友善的回复…
发表回复
szjarvis 2011-08-13
  • 打赏
  • 举报
回复
好东西要收藏.
nandianxia 2010-12-10
  • 打赏
  • 举报
回复
好东西 谢分享
guolunfeng 2010-06-25
  • 打赏
  • 举报
回复
mark
  • 打赏
  • 举报
回复
mark
cadust 2009-02-25
  • 打赏
  • 举报
回复
Mark!!!!!!!
huadiw 2008-12-13
  • 打赏
  • 举报
回复
MARK下来!
wangfeng8317 2008-12-10
  • 打赏
  • 举报
回复
慢慢研究
chinaxc 2008-11-26
  • 打赏
  • 举报
回复
两种不同形式的分页,来晚了没分。晕。。。。。。。。。。。。
chinaxc 2008-11-26
  • 打赏
  • 举报
回复

public string Mepage(int Mcount, int pagesize, string Mepostbackurl, string Meurlstr, string Meurlpage)
{
int num;
int num2;
StringBuilder builder = new StringBuilder();
string str = Meurlstr + Meurlpage;
if ((HttpContext.Current.Request.QueryString[Meurlpage] != null) && int.TryParse(HttpContext.Current.Request.QueryString[Meurlpage], out num))
{
num2 = Convert.ToInt32(HttpContext.Current.Request.QueryString[Meurlpage]);
}
else
{
num2 = 1;
}
int num3 = Mcount / pagesize;
if (num3 == 0)
{
num3 = 1;
}
else if ((Mcount % pagesize) > 0)
{
num3++;
}
builder.Append("<table><tr>");
builder.Append("<td>");
builder.Append("共有条" + Mcount.ToString() + "记录 ");
builder.Append(string.Concat(new object[] { "当前是第", num2, "/", num3, "页 " }));
if (num3 == 1)
{
builder.Append("首页 ");
builder.Append("上一页 ");
builder.Append("下一页 ");
builder.Append("最后一页");
}
else if (num2 == 1)
{
builder.Append("首页 ");
builder.Append("上一页 ");
builder.Append(string.Concat(new object[] { "<a href=", Mepostbackurl, "?", str, "=", num2 + 1, ">下一页</a> " }));
builder.Append(string.Concat(new object[] { "<a href=", Mepostbackurl, "?", str, "=", num3, ">最后一页</a>" }));
}
else if (num2 >= num3)
{
builder.Append("<a href=" + Mepostbackurl + "?" + str + "=1>首页</a> ");
builder.Append(string.Concat(new object[] { "<a href=", Mepostbackurl, "?", str, "=", num2 - 1, ">上一页</a> " }));
builder.Append("下一页 ");
builder.Append("最后一页");
}
else
{
builder.Append("<a href=" + Mepostbackurl + "?" + str + "=1>首页</a> ");
builder.Append(string.Concat(new object[] { "<a href=", Mepostbackurl, "?", str, "=", num2 - 1, ">上一页</a> " }));
builder.Append(string.Concat(new object[] { "<a href=", Mepostbackurl, "?", str, "=", num2 + 1, ">下一页</a> " }));
builder.Append(string.Concat(new object[] { "<a href=", Mepostbackurl, "?", str, "=", num3, ">最后一页</a>" }));
}
builder.Append("</td>");
builder.Append("<td><select id=\"MeSelectPage\" onchange=\"window.location='" + Mepostbackurl + "?" + str + "='+this.options[this.selectedIndex].value\">\r\n");
for (int i = 1; i < (num3 + 1); i++)
{
if ((HttpContext.Current.Request.QueryString[Meurlpage] != null) && (HttpContext.Current.Request.QueryString[Meurlpage].ToString() == i.ToString()))
{
builder.Append(string.Concat(new object[] { "<option value=", i, " selected>", i, "页</option>\r\n" }));
}
else
{
builder.Append(string.Concat(new object[] { "<option value=", i, ">", i, "页</option>\r\n" }));
}
}
builder.Append("</select></td>\r\n");
builder.Append("</tr></table>");
return builder.ToString();
}





chinaxc 2008-11-26
  • 打赏
  • 举报
回复
public string MyPage(int Myallcount, int Mypagesize, int Mypageshowsize, string Mypostbackurl, string Myurlstr, string Myurlpage, string Mycolor, string Myfontcolor, string Mybordercolor)
{
StringBuilder builder = new StringBuilder();
StringBuilder builder2 = new StringBuilder();
string str = Myurlstr + Myurlpage;
int num = Myallcount / Mypagesize;
if (num == 0)
{
num = 1;
}
else if ((Myallcount % Mypagesize) > 0)
{
num++;
}
int num3 = 0;
if (Myallcount > 0)
{
int num2;
int num4;
int num5;
builder.Append("<td class=pagefalse><a href=#>共有" + Myallcount + "条记录</a></td>\r\n");
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=1 title=首页>首页</a></td>\r\n");
if (!(((HttpContext.Current.Request.QueryString[Myurlpage] != null) && (HttpContext.Current.Request.QueryString[Myurlpage].ToString() != null)) && int.TryParse(HttpContext.Current.Request.QueryString[Myurlpage], out num4)))
{
num2 = 1;
}
else
{
num2 = Convert.ToInt32(HttpContext.Current.Request.QueryString[Myurlpage]);
}
if (num < Mypageshowsize)
{
for (num5 = (num2 / Mypageshowsize) + 1; num5 <= num; num5++)
{
if (num2 == num5)
{
builder.Append("<td class=pagetrue><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
else
{
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
}
}
else if ((num2 / Mypageshowsize) > 0)
{
builder.Append(string.Concat(new object[] { "<td class=pagefalse><a href=", Mypostbackurl, "?", str, "=", Convert.ToInt32((int) (((num2 / Mypageshowsize) * Mypageshowsize) - 1)), " title=上一组>.....</a></td>\r\n" }));
if ((num2 / Mypageshowsize) < (num / Mypageshowsize))
{
for (num5 = (num2 / Mypageshowsize) * Mypageshowsize; num5 <= (((num2 / Mypageshowsize) + 1) * Mypageshowsize); num5++)
{
if (num2 == num5)
{
builder.Append("<td class=pagetrue><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
else
{
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
}
num3 = ((num2 / Mypageshowsize) + 1) * Mypageshowsize;
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=" + num3.ToString() + " title=下一组>.....</a></td>\r\n");
}
else
{
for (num5 = (num2 / Mypageshowsize) * Mypageshowsize; num5 <= num; num5++)
{
if (num2 == num5)
{
builder.Append("<td class=pagetrue><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
else
{
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
}
num3 = num;
}
}
else
{
for (num5 = (num2 / Mypageshowsize) + 1; num5 <= Mypageshowsize; num5++)
{
if (num2 == num5)
{
builder.Append("<td class=pagetrue><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
else
{
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
}
num3 = ((num2 / Mypageshowsize) + 1) * Mypageshowsize;
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=" + num3.ToString() + " title=下一组>.....</a></td>\r\n");
}
builder.Append("<td><select id=\"MySelectPage\" onchange=\"window.location='" + Mypostbackurl + "?" + str + "='+this.options[this.selectedIndex].value\">\r\n");
for (int i = 1; i < (num + 1); i++)
{
if ((HttpContext.Current.Request.QueryString[Myurlpage] != null) && (HttpContext.Current.Request.QueryString[Myurlpage].ToString() == i.ToString()))
{
builder.Append(string.Concat(new object[] { "<option value=", i, " selected>", i, "页</option>\r\n" }));
}
else
{
builder.Append(string.Concat(new object[] { "<option value=", i, ">", i, "页</option>\r\n" }));
}
}
builder.Append("</select></td>\r\n");
builder.Append(string.Concat(new object[] { "<td class=pagefalse><a href=", Mypostbackurl, "?", str, "=", num, " title=最后一页>最后一页</a></td>\r\n" }));
}
else
{
builder.Append("<td>抱歉没有数据</td>");
}
builder2.Append("<style>\r\n");
builder2.Append(".pageborder A:active,.pageborder A:hover,.pageborder A:visited,.pageborder A:link {\r\n");
builder2.Append("DISPLAY: block;COLOR: #686868;TEXT-DECORATION: none;font-size:14px;text-align:center;\r\n");
builder2.Append("border: 1px solid " + Mybordercolor + ";}\r\n");
builder2.Append(".pagefalse A:link,.pagefalse A:visited,.pagefalse A:active,.pagefalse A:hover {padding:3px;}\r\n");
builder2.Append(".pagetrue A:link,.pagetrue A:visited,.pagetrue A:active,.pagetrue A:hover {\r\n");
builder2.Append("padding:5px;background-color:" + Mycolor + ";color:" + Myfontcolor + ";}\r\n");
builder2.Append("</style>\r\n");
builder2.Append("<table cellspacing=0 class=pageborder>\r\n");
builder2.Append("<tr>\r\n");
builder2.Append(builder.ToString() + "\r\n");
builder2.Append("</tr>\r\n");
builder2.Append("</table>\r\n");
return builder2.ToString();
}

格拉 2008-11-12
  • 打赏
  • 举报
回复
mark!
qwashhtt 2008-11-11
  • 打赏
  • 举报
回复
一直看完了才知道是C#的,我说怎么全是没见过的。
qwashhtt 2008-11-11
  • 打赏
  • 举报
回复
一直看完了才知道是C#的,我说怎么全是没见过的。
shibk0431 2008-11-10
  • 打赏
  • 举报
回复
谢谢
LZ 帮助!!!!1
deepinnet 2008-11-09
  • 打赏
  • 举报
回复
服务器提交了协议冲突
lianhunqianr 2008-11-07
  • 打赏
  • 举报
回复
什么语音写的??
yanbeifei168 2008-11-07
  • 打赏
  • 举报
回复
回帖是一种美德!传说每天回帖即可获得 10 分可用分!
egxsun 2008-11-06
  • 打赏
  • 举报
回复
谢谢!
liuxing142 2008-11-06
  • 打赏
  • 举报
回复
呵呵 辛苦了……
Mr_Tan 2008-11-06
  • 打赏
  • 举报
回复
转转
加载更多回复(217)

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧