扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:佚名 来源:Microsoft 2007年11月8日
关键字: Windows
public class SqlPager : WebControl, INamingContainer { ... } |
protected override void CreateChildControls() { // 清除现有的子控件及其 ViewState Controls.Clear(); ClearChildViewState(); // 生成控件树 BuildControlHierarchy(); } |
private void BuildControlHierarchy() { // 生成环境表格(一行,两个单元格) Table t = new Table(); t.Font.Name = this.Font.Name; t.Font.Size = this.Font.Size; t.BorderStyle = this.BorderStyle; t.BorderWidth = this.BorderWidth; t.BorderColor = this.BorderColor; t.Width = this.Width; t.Height = this.Height; t.BackColor = this.BackColor; t.ForeColor = this.ForeColor; // 生成表格中的行 TableRow row = new TableRow(); t.Rows.Add(row); // 生成带有导航条的单元格 TableCell cellNavBar = new TableCell(); if (PagerStyle == this.PagerStyle.NextPrev) BuildNextPrevUI(cellNavBar); else BuildNumericPagesUI(cellNavBar); row.Cells.Add(cellNavBar); // 生成带有页面索引的单元格 TableCell cellPageDesc = new TableCell(); cellPageDesc.HorizontalAlign = HorizontalAlign.Right; BuildCurrentPage(cellPageDesc); row.Cells.Add(cellPageDesc); // 将表格添加到控件树 this.Controls.Add(t); } |
private void BuildNextPrevUI(TableCell cell) { bool isValidPage = ((CurrentPageIndex >=0) && (CurrentPageIndex <= TotalPages-1)); bool canMoveBack = (CurrentPageIndex>0); bool canMoveForward = (CurrentPageIndex<TotalPages-1); // 显示 << 按钮 LinkButton first = new LinkButton(); first.ID = "First"; first.Click += new EventHandler(first_Click); first.Font.Name = "webdings"; first.Font.Size = FontUnit.Medium; first.ForeColor = ForeColor; first.ToolTip = "第一页"; first.Text = "7"; first.Enabled = isValidPage && canMoveBack; cell.Controls.Add(first); : } |
private void BuildNumericPagesUI(TableCell cell) { // 显示一个下拉列表 DropDownList pageList = new DropDownList(); pageList.ID = "PageList"; pageList.AutoPostBack = true; pageList.SelectedIndexChanged += new EventHandler(PageList_Click); pageList.Font.Name = this.Font.Name; pageList.Font.Size = Font.Size; pageList.ForeColor = ForeColor; if (TotalPages <=0 || CurrentPageIndex == -1) { pageList.Items.Add("No pages"); pageList.Enabled = false; pageList.SelectedIndex = 0; } else // 填充列表 { for(int i=1; i<=TotalPages; i++) { ListItem item = new ListItem(i.ToString(), (i-1).ToString()); pageList.Items.Add(item); } pageList.SelectedIndex = CurrentPageIndex; } } |
private void first_Click(object sender, EventArgs e) { GoToPage(0); } private void PageList_Click(object sender, EventArgs e) { DropDownList pageList = (DropDownList) sender; int pageIndex = Convert.ToInt32(pageList.SelectedItem.Value); GoToPage(pageIndex); } private void GoToPage(int pageIndex) { // 准备事件数据 PageChangedEventArgs e = new PageChangedEventArgs(); e.OldPageIndex = CurrentPageIndex; e.NewPageIndex = pageIndex; // 更新当前的索引 CurrentPageIndex = pageIndex; // 启动页面更改事件 OnPageIndexChanged(e); // 绑定新数据 DataBind(); } |
public int CurrentPageIndex { get {return Convert.ToInt32(ViewState["CurrentPageIndex"]);} set {ViewState["CurrentPageIndex"] = value;} } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者