ASP.Net 頁面中GirdView 源碼內容說明

在界面中添加了GirdView控件並增加數據源之后,在代碼中可以看見它的內容。

    <div>
        
<asp:GridView ID="GridView1" runat="server" DataSourceID="EventDataSource" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" GridLines="None">
            
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
            
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
            
<Columns>
                
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
                
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                
<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
                
<asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" />
            
</Columns>
            
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
            
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
            
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
        
</asp:GridView>

        
<asp:SqlDataSource ID="EventDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:EventsConnectionString %>"
            SelectCommand
="SELECT [Id], [Title], [Date], [Location] FROM [Events]"></asp:SqlDataSource> 
    
</div>

說明:
    DataSourceID
定義了與數據源控件的關聯。(DataSourceID="EventDataSource")
    <Columns></Columns>
列出了用於顯示數據的所有綁定列
    HeaderText
此列的標題
    DataField
數據源中的字段名
    <asp:SqlDataSource></asp:SqlDataSource>
定義婁數據源
    SelectCommand
定義如何從數據庫中讀取數據
    ConnectionString
定義如何連接數據庫(ConnectionString="<%$ ConnectionStrings:EventsConnectionString %>"),連接字符串我們保存在配置文件web.config中,所以用<%$ 與配置文件中動態生成的類之間建立關聯。

原文地址:https://www.cnblogs.com/scottckt/p/1157002.html