📄 calculatedcolumn.aspx
字号:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat=server>
void Page_Load(Object sender , EventArgs e)
{
DataSet dstProducts;
SqlConnection conNorthwind;
SqlDataAdapter dadProducts;
DataColumn dcolSalePrice;
//Grab the products table
dstProducts = new DataSet();
conNorthwind = new SqlConnection( @"Server=localhost;Integrated Security=SSPI;Database=Northwind" );
dadProducts = new SqlDataAdapter( "Select * From Products", conNorthwind );
dadProducts.Fill( dstProducts, "Products" );
//Add the calculated column
dcolSalePrice = new DataColumn( "SalePrice", typeof( Decimal ) );
dcolSalePrice.Expression = "UnitPrice - (UnitPrice * .10)";
dstProducts.Tables[ "Products" ].Columns.Add( dcolSalePrice );
//Bind to the DataGrid
dgrdProducts.DataSource = dstProducts;
dgrdProducts.DataBind();
}
</Script>
<html>
<head><title>CalculatedColumn.aspx</title></head>
<body>
<asp:DataGrid
ID="dgrdProducts"
Runat="Server" />
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -