| 属性 | 描述 |
|---|---|
| DataSource | 数据源, |
| BorderColor | |
| BackColor | |
| FooterStyle | |
| SelectedItemStyle | |
| AlternatingItemStyle | |
| ItemStyle | |
| HeaderStyle | |
| AutoGenerateColumns | 是否自动生成列 |
| AllowPaging | 是否自动分页 |
| PageSize | |
| PaperStyle.HorizontalAlign | 页码放置位置 |
| PaperStyle.Mode | 分页符号样式 |
| OnPageIndexChanged | 设置为分页时调用的事件名称 |
| OnEditCommand | |
| OnUpdateCommand | |
| OnCancelCommand |
| <%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { SqlConnection connection = new SqlConnection(); connection.ConnectionString = "Server=mypc;Database=asteras;Trusted_Connection=true"; connection.Open(); SqlCommand command = connection.CreateCommand(); command.CommandText = "getdata"; SqlDataReader datareader; datareader = command.ExecuteReader(); datagrid1.DataSource = datareader; datagrid1.DataBind(); datareader.Close(); connection.Close(); datareader.Dispose(); command.Dispose(); connection.Dispose(); } </script> <html> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <asp:DataGrid runat=server ID=datagrid1 /> </form> </body> </html> |