⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 create-new-datatable.aspx

📁 东软内部材料(四)asp等相关的教学案例 
💻 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 + -