📄 autocolumn.aspx
字号:
<%@ Page Debug="true" Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>DataGrid Demo- Auto Generate</title>
<script language="C#" runat="server" >
public void Page_Load()
{
//Create Connection object
string dataSource = "Data Source=localhost;";
string security = "user id=sa; password=;";
string initialCatalog = "initial catalog=pubs;";
string cnnString = dataSource + security + initialCatalog;
SqlConnection connection = new SqlConnection(cnnString);
// Create Data Command
string strSql = "select * from [authors]";
SqlCommand command = new SqlCommand(strSql, connection);
// Create Data Adapter
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = command;
// Create DataSet
DataSet dataSet = new DataSet();
try
{
connection.Open();
adapter.Fill(dataSet);
}
catch(SqlException e)
{
Response.Write(e.ToString());
}
finally
{
connection.Close();
}
grid1.DataSource = dataSet.Tables[0];
grid1.DataBind();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>DataGrid Demo- Auto Generate</h3>
<asp:DataGrid id="grid1" runat="server" ShowHeader="true" GridLines="Both" AutoGenerateColumns="true">
<HeaderStyle BackColor="lightblue" Font-Name="Arial" Font-Bold="true" />
<ItemStyle BackColor="lightyellow"/>
</asp:DataGrid>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -