沉重的打击,想尽办法法做的控件却没有实现分页功能,请思归看一下!

ahking 2003-07-28 06:30:06
protected override void CreateChildControls()
{


//以下创建表格行

int nEndcount;
if(nStartcount+PageSize>=dtbname.Rows.Count)
{
nEndcount=dtbname.Rows.Count;}
else
{
nEndcount=nStartcount+PageSize;
}

HyperLink[] dtkey=new HyperLink[dtbname.Rows.Count+2];
for (int i=nStartcount; i < nEndcount; i++)
{

trcontent =new TableRow();
Controls.Add(trcontent);
trcontent.BackColor=System.Drawing.ColorTranslator.FromHtml(Trbgcolor);
//第一列加连接
TableCell tc = new TableCell();
trcontent.Cells.Add(tc);
dtkey[i]=new HyperLink();
dtkey[i].Text=dtbname.Rows[i][Dt_guid].ToString();
dtkey[i].NavigateUrl=Linkpage+"?"+Trans_guid+"="+Dt_guid;
tc.Controls.Add(dtkey[i]);


for (int j=1; j < Columnum; j++)
{
TableCell tco = new TableCell();
tco.Text=dtbname.Rows[i][j].ToString();
trcontent.Cells.Add(tco);

}
}






//以下创建linkbutton
nagrow = new TableRow();
Controls.Add(nagrow);
TableCell nagcell = new TableCell();
nagrow.Cells.Add(nagcell);
int nTotalCount=Dtbname.Rows.Count;
nTotalPage = nTotalCount/PageSize;
nTotalPage += nTotalCount % PageSize > 0? 1:0;
LinkButton[] GoPage=new LinkButton[nTotalPage+2];
for(int n=1;n<=nTotalPage;n++)
{


GoPage[n]=new LinkButton();
GoPage[n].Text=n.ToString();
GoPage[n].ID="GoPage"+n.ToString();
GoPage[n].Click+=new EventHandler(this.Gopageclicked);
nagcell.Controls.Add(GoPage[n]);


}




}

private void Gopageclicked(Object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;

nStartcount=PageSize*(System.Convert.ToInt16(lb.ID.Substring(6))-1);




}
...全文
25 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
mnm0756 2003-07-31
  • 打赏
  • 举报
回复
BeyondLove2000(马) 可以给我一份吗?
mnm35@sina.com.cn
ahking 2003-07-30
  • 打赏
  • 举报
回复
我仔细研究过你的代码,但有些功能没有实现,我应该在哪里创建hyperlink呢?我是按照你讲的创建linkbutton方法创建的啊。
saucer 2003-07-30
  • 打赏
  • 举报
回复
the reason is that you are creating the hyperlink controls before the Page index is changed!

I posted the code for a PageControl in your post before, if you carefully studied it, you will see how to do it
ahking 2003-07-30
  • 打赏
  • 举报
回复
圆满解决,感谢各位
虚拟过客 2003-07-30
  • 打赏
  • 举报
回复
gz
ahking 2003-07-30
  • 打赏
  • 举报
回复
看看:ahking2000@163.com
BeyondLove2000 2003-07-30
  • 打赏
  • 举报
回复
可以给你一个例子,完全实现了的,邮箱:
ahking 2003-07-30
  • 打赏
  • 举报
回复
up
ahking 2003-07-29
  • 打赏
  • 举报
回复
up
ahking 2003-07-29
  • 打赏
  • 举报
回复
up
ahking 2003-07-29
  • 打赏
  • 举报
回复
属性只有 nStartcount用到了viewstate,不知有无影响?
private DataTable dtbname;

[Bindable(true),
Category("data"),
DefaultValue("")]
public DataTable Dtbname
{
get
{
return dtbname;
}

set
{
dtbname = value;
}
}

//每页记录数
private int pageSize;
[Bindable(true),
Category("data"),
DefaultValue("")]

public int PageSize
{
get
{
return pageSize;

}

set
{
pageSize = value;

}
}
//开始记录

public int nStartcount
{
get
{
if (ViewState["nStartcount"] == null)
return 0;
return (int)ViewState["nStartcount"];
}
set
{
ViewState["nStartcount"] = value;
}
}
ahking 2003-07-29
  • 打赏
  • 举报
回复
问题是:只有点击两次linkbutton按钮才能跳转到相应的页面,怎么回事??
ken2003 2003-07-29
  • 打赏
  • 举报
回复
up
ahking 2003-07-28
  • 打赏
  • 举报
回复
help
ahking 2003-07-28
  • 打赏
  • 举报
回复
up
warren1999 2003-07-28
  • 打赏
  • 举报
回复
up
ken2003 2003-07-28
  • 打赏
  • 举报
回复
up
ahking 2003-07-28
  • 打赏
  • 举报
回复
?
ahking 2003-07-28
  • 打赏
  • 举报
回复
help
ahking 2003-07-28
  • 打赏
  • 举报
回复
up

62,242

社区成员

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

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

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

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