asp.net 2.0控制項一些有可能是bug的小問題:

來源:互聯網
上載者:User

(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,應該要有所體現,然而沒有,我們不得不通過下面的代碼才能讓列頭不用粗體顯示:1protected 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)在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個儲存格。


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.