(1)不允许重新绑定的情况下,编码设置ShowHeader,ShowFooter属性:
页面上放一个 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="5" ShowFooter="True" AllowSorting="True"> </asp:GridView>
不使用DataSource控件,而是用编程方式对其进行绑定; 有两个按钮,一个是将ShowHeader,ShowFooter属性设置为True,另一个则是设置为False。执行,点击ButtonF,一次没反应,点两次,Header和Footer都不见了;再点击ButtonT,Header和Footer可能就不会再显示了。
用DataSource控件进行绑定就不会有这个问题,但是,这会自动从数据库读取数据并重新绑定。
1protected void Page_Load(object sender, EventArgs e)
2 {
3 if (!IsPostBack) this.BindTestData();
4 }
5 protected void BindTestData()
6 {
7 //编码获取原始数据并绑定到GridView
8 }
9 protected void ButtonT_Click(object sender, EventArgs e)
10 {
11 this.GridView1.ShowHeader = true;
12 this.GridView1.ShowFooter = true;
13 //this.GridView1.AllowPaging = true;
14
15 }
16 protected void ButtonF_Click(object sender, EventArgs e)
17 {
18 this.GridView1.ShowHeader = false;
19 this.GridView1.ShowFooter = false;
20 //this.GridView1.AllowPaging = false;
21
22 }
(2)设置GridView的HeaderStyle.Font.Bold属性为False,没有效果:
这只是个小问题而已,但是明显是不对的。GridView控件的列头,会生成<th></th>标签,但是如果用户设置了该属性为False,应该要有所体现,然而没有,我们不得不通过下面的代码才能让列头不用粗体显示:
1
protected
void
GridView1_RowDataBound(
object
sender, GridViewRowEventArgs e)
2 {
3 if (e.Row.RowType == DataControlRowType.Header)
4 {
5 foreach(TableCell cell in e.Row.Cells)
6 cell.Attributes.Add("style","FONT-WEIGHT:normal");
7 }
8 }
9
2 {
3 if (e.Row.RowType == DataControlRowType.Header)
4 {
5 foreach(TableCell cell in e.Row.Cells)
6 cell.Attributes.Add("style","FONT-WEIGHT:normal");
7 }
8 }
9
(3)在asp.net 2.0中使用DataGrid控件,在下面的特定情况下Pager的样式会有变化:
<
asp:DataGrid
ID
="DataGrid1"
runat
="server"
AllowPaging
="True"
PageSize
="2"
AutoGenerateColumns
="False"
>
< Columns >
< asp:BoundColumn DataField ="id" HeaderText ="ID" ></ asp:BoundColumn >
< asp:BoundColumn DataField ="name" HeaderText ="NAME" ></ asp:BoundColumn >
< asp:BoundColumn DataField ="sex" HeaderText ="SEX" ></ asp:BoundColumn >
< asp:TemplateColumn HeaderText ="选择" >< ItemTemplate >
< asp:LinkButton id ="LinkButton1" runat ="server" Text ='<%# DataBinder.Eval(Container, "DataItem.Name") % > ' CommandName="Select"> </ asp:LinkButton >
</ ItemTemplate ></ asp:TemplateColumn >
</ Columns >
< PagerStyle HorizontalAlign ="Center" />
</ asp:DataGrid >
绑定到DataSource控件或编码绑定到DataView,执行,尝试点击模版列中的LinkButton,Pager的样式会发生变化,原先整行的Pager变成了2个单元格。
< Columns >
< asp:BoundColumn DataField ="id" HeaderText ="ID" ></ asp:BoundColumn >
< asp:BoundColumn DataField ="name" HeaderText ="NAME" ></ asp:BoundColumn >
< asp:BoundColumn DataField ="sex" HeaderText ="SEX" ></ asp:BoundColumn >
< asp:TemplateColumn HeaderText ="选择" >< ItemTemplate >
< asp:LinkButton id ="LinkButton1" runat ="server" Text ='<%# DataBinder.Eval(Container, "DataItem.Name") % > ' CommandName="Select"> </ asp:LinkButton >
</ ItemTemplate ></ asp:TemplateColumn >
</ Columns >
< PagerStyle HorizontalAlign ="Center" />
</ asp:DataGrid >