DataGrid风格样式:FooterStyle,HeaderStyle,PagerStyle,SelectedItemStyle,ItemStyle

发布时间:2020-03-17编辑:脚本学堂
本文分享一个asp.net datagrid的例子,学习下其样式风格的用法,包括FooterStyle,HeaderStyle,PagerStyle,SelectedItemStyle,ItemStyle。有需要的朋友参考下。

asp.net中datagrid有多种风格样式,可自由设置。
它们分别是:FooterStyle,HeaderStyle,PagerStyle,SelectedItemStyle,ItemStyle

代码:
 

复制代码 代码示例:

<%@ Page Language="VB" %>
<script runat="server">
  Function AllDiscs() As System.Data.SqlClient.SqlDataReader
    Dim connectionString As String = "server='(local)NetSDK'; trusted_connection=true; Database='CAM'"
    Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)
   
    Dim queryString As String = "SELECT * FROM Employee"
    Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
   
    sqlConnection.Open
    Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
   
    Return dataReader
  End Function
   
  Sub Page_Load(sender As Object, e As EventArgs)
   
    DataGrid1.DataBind()
   
  End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <asp:DataGrid id="DataGrid1" runat="server" DataSource="<%# AllDiscs() %>" BorderStyle="None" BorderWidth="1px" BorderColor="#CC9966" BackColor="White" CellPadding="4">
            <FooterStyle forecolor="#330099" backcolor="#FFFFCC"></FooterStyle>
            <HeaderStyle font-bold="True" forecolor="#FFFFCC" backcolor="#990000"></HeaderStyle>
            <PagerStyle horizontalalign="Center" forecolor="#330099" backcolor="#FFFFCC"></PagerStyle>
            <SelectedItemStyle font-bold="True" forecolor="#663399" backcolor="#FFCC66"></SelectedItemStyle>
            <ItemStyle forecolor="#330099" backcolor="White"></ItemStyle>
        </asp:DataGrid>
    </form>
</body>
</html>