(1) If re-binding is not allowed, set the ShowHeader and ShowFooter attributes for encoding:
Put a <asp: gridView ID = "GridView1" runat = "server" AllowPaging = "True" PageSize = "5" ShowFooter = "True" AllowSorting = "True"> </asp: GridView>
Instead of using the DataSource control, it is programmed to bind it. There are two buttons. One is to set the ShowHeader, ShowFooter attribute to True, and the other is to False. Execute and click ButtonF. No response is returned at a time. Click it twice and the Header and Footer are lost. Click ButtonT again. The Header and Footer may not be displayed.
This problem does not occur if you bind data using the DataSource control. However, this will automatically read data from the database and rebind the data.
1 protected void Page_Load (object sender, EventArgs e)
2 {
3 if (! IsPostBack) this. BindTestData ();
4}
5 protected void BindTestData ()
6 {
7 // code to get the original data and bind it to the 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) set the HeaderStyle. Font. Bold attribute of the GridView to False, with no effect:
This is only a small problem, but it is obviously incorrect. The <th> </th> label is generated for the column header of the GridView control. However, if you set this attribute to False, it must be reflected, we have to use the following code to make the column header not show in bold: 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
(3) when using the DataGrid Control in asp.net 2.0, the Pager style may change in the following situations:
<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 = "select"> <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>
Bind the data source control or code to DataView. Run the command and click the LinkButton in the template column. The Pager style changes. The Pager of the entire row is changed to two cells.