首页 新闻 会员 周边

扩展GridView的功能,重写了InitializePager方法的问题。

0
[已关闭问题]

    我重写了GridVIew的InitializePager方法, 在里面添加了Table, TD里面增加了文本框, 我在控件里面要如何取得这个文本框的值? 代码如下:

 

代码
1 protected override void InitializePager(GridViewRow row, int columnSpan, PagedDataSource pagedDataSource)
2 {
3 if (PagerType == ThisPagerType.Regular)
4 {
5 // if PagerType is not DropDownList
6 // render the regular GridView Pager
7   base.InitializePager(row, columnSpan, pagedDataSource);
8 }
9 else
10 {
11 TableCell cell_1;
12 // if we are going to use dropdownlist
13 if (PagerType == ThisPagerType.DropDownList)
14 {
15 // our Pager with DropDownList control
16
17 // create our DropDownList control
18 var ddl = new DropDownList();
19 // populate it with the number of Pages of our GridView
20 for (int i = 0; i < PageCount; i++)
21 {
22 ddl.Items.Add(new ListItem(Convert.ToString(i + 1), i.ToString()));
23 }
24 ddl.AutoPostBack = true;
25 // assign an Event Handler when its Selected Index Changed
26 ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
27 // synchronize its selected index to GridView's current PageIndex
28 ddl.SelectedIndex = PageIndex;
29
30 // add our first TableCell which will contain the DropDownList
31 cell_1 = new TableCell();
32
33 // we just add a Label with 'Page ' Text
34 cell_1.Controls.Add(PageOf());
35
36 // our DropDownList control here.
37 cell_1.Controls.Add(ddl);
38
39 // and our Total number of Pages
40 cell_1.Controls.Add(PageTotal());
41 }
42 else
43 {
44 // if we are going to use the FirstPrevNextLast buttons.
45 LinkButton first = new LinkButton();
46 first.Text = "首页 ";
47 // first button will always have a value of zero (0)
48 first.CommandArgument = "0";
49 first.Enabled = PageIndex > 0;
50 // add click event handler
51 first.Click += new EventHandler(navigate_Click);
52
53 LinkButton prev = new LinkButton();
54 prev.Text = "上一页 ";
55 // set Prev button argument's to current PageIndex minus 1
56 prev.CommandArgument = string.Format("{0}", (PageIndex - 1));
57 prev.Enabled = (PageIndex > 0);
58 prev.Click += new EventHandler(navigate_Click);
59
60 LinkButton next = new LinkButton();
61 next.Text = "下一页";
62 // set Next button argument's to current PageIndex plus 1
63 next.CommandArgument = string.Format("{0}", (PageIndex + 1));
64 next.Enabled = (PageIndex < (PageCount - 1));
65 next.Click += new EventHandler(navigate_Click);
66
67 LinkButton last = new LinkButton();
68 last.Text = "尾页";
69 // Last button will always have a value equal to PageCount minus 1
70 last.CommandArgument = string.Format("{0}", (PageCount - 1));
71 last.Enabled = (PageIndex < (PageCount - 1));
72 last.Click += new EventHandler(navigate_Click);
73
74
75 TextBox navTb = new TextBox();
76 navTb.Width = 30
;
77
78
79 LinkButton navLink = new LinkButton();
80 navLink.Text = "跳转到";
81 // Last button will always have a value equal to PageCount minus 1
82 navLink.CommandArgument = navTb.Text.Equals("")?"0":navTb.Text;
83 // navLink.Enabled = (PageIndex < (PageCount - 1));
84 navLink.Click += new EventHandler(navigate_Click);
85
86
87 cell_1 = new TableCell();
88
89 // add the First button to cell controls collection
90 cell_1.Controls.Add(first);
91 // add the Prev button
92 cell_1.Controls.Add(prev);
93 // add the Next button
94 cell_1.Controls.Add(next);
95 // add the Last button
96 cell_1.Controls.Add(last);
97
98
99 cell_1.Controls.Add(navTb);
100 cell_1.Controls.Add(navLink);
101 }
102
103 // create a Table that will replace entirely our GridView's Pager section
104 Table tbl = new Table();
105 tbl.BorderWidth = 0;
106 tbl.Width = Unit.Percentage(100);
107 // add one TableRow to our Table
108 tbl.Rows.Add(new TableRow());
109
110 // the 2nd TableCell will display the Record number you are currently in.
111 TableCell cell_2 = new TableCell();
112 cell_2.Controls.Add(PageInfo(pagedDataSource.DataSourceCount));
113
114 // add now the 2 cell to our created row
115 tbl.Rows[0].Cells.Add(cell_1);
116 tbl.Rows[0].Cells.Add(cell_2);
117 tbl.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Left;
118 tbl.Rows[0].Cells[1].HorizontalAlign = HorizontalAlign.Right;
119
120 // in Pager's Row of our GridView add a TableCell
121 row.Controls.AddAt(0, new TableCell());
122 // sets it span to GridView's number of columns
123 row.Cells[0].ColumnSpan = Columns.Count;
124 // finally add our created Table
125 row.Cells[0].Controls.AddAt(0, tbl);
126
127 }
128 }

红色部分, 要取那个Textbox的值, 怎么去取, 是一个文本框做跳转输入数字的。

问天何必的主页 问天何必 | 老鸟四级 | 园豆:3311
提问于:2010-01-29 09:44
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册