作了个自定义控件。代码测试没有问题,可就是控件不能显示数据??? 1.数据库方面没有问题2.加载也没有发现啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 控件是我自定义的没有啊namespace Witkey.Web{ /// <summary> /// CustomList 的摘要说明 /// </summary> 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); } } } 关于datagridview存入txt Js 怎么构建树 ——求C# 相关外文+ 翻译一份!!! winform下的splitContainer问题 谁共享下C#开发的农场外挂的东西,或给点有用的参考信息 .net控制台应用程序怎么发布的? 使用数据库来控制模块 datagridview 中.怎么在指定位置添加新行? 我在原窗体的基础上又新建了一个窗体,为和新建的那个窗体把Pocket pC2002下的输入法的那个任务栏给当住了,我没法选择输入法了?? 无不无聊。。天天必败什么的。。。 取位查询??搞了很多天觉得有点难请教! C#技术问题
namespace Witkey.Web
{ /// <summary>
/// CustomList 的摘要说明
/// </summary>
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);
}
}
}