?? create-new-datatable.aspx
字號:
<%@Page Language="C#"%>
<%@Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Creating and Populating a new DataTable</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Creating and Populating a new DataTable</span><hr />
<!--------------------------------------------------------------------------->
<asp:datagrid id="dgrResult" runat="server" />
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
// create a new empty Table object
DataTable objTable = new DataTable("newTable");
// define four columns (fields) within the table
objTable.Columns.Add("ISBN", Type.GetType("System.String"));
objTable.Columns.Add("Title", Type.GetType("System.String"));
objTable.Columns.Add("PublicationDate", Type.GetType("System.DateTime"));
objTable.Columns.Add("Quantity", Type.GetType("System.Int32"));
// declare a variable to hold a DataRow object
DataRow objDataRow;
// create a new DataRow object instance in this table
objDataRow = objTable.NewRow();
// and fill in the values
objDataRow["ISBN"] = "1234567800";
objDataRow["Title"] = "Professional Video Recorder Programming";
objDataRow["PublicationDate"] = new DateTime(2001, 3, 1);
objDataRow["Quantity"] = 3956;
objTable.Rows.Add(objDataRow);
// repeat to add two more rows
objDataRow = objTable.NewRow();
objDataRow["ISBN"] = "1234567801";
objDataRow["Title"] = "Professional WAP Phone Programming";
objDataRow["PublicationDate"] = new DateTime(2001, 6, 1);
objDataRow["Quantity"] = 29;
objTable.Rows.Add(objDataRow);
objDataRow = objTable.NewRow();
objDataRow["ISBN"] = "1234567802";
objDataRow["Title"] = "Professional Radio Station Programming";
objDataRow["PublicationDate"] = new DateTime(2001, 4, 1);
objDataRow["Quantity"] = 10456;
objTable.Rows.Add(objDataRow);
// assign the DataTable// s DefaultView object to the DataGrid control
dgrResult.DataSource = objTable.DefaultView;
dgrResult.DataBind(); // and bind (display) the data
}
</script>
<!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -