在中多數據綁定的控件很多
(
DataGrid
(
DataGrid
說明
e表示System
DataGrid
DataGrid
DataGrid
下面我使用了
(
(
(
(
備注
下面以獲取Northwind數據庫的Customers表的數據為列
序號
序號
序號
序號
序號
CustomerID
LONEP
MAGAA
MAISD
MEREP
MORGK
NORTS
OCEAN
OLDWO
OTTIK
PARIS
<%@ Page language=
<!DOCTYPE HTML PUBLIC
<HTML>
<HEAD>
<title>WebForm
<meta content=
<meta content=
<meta content=
<meta content=
</HEAD>
<body>
<form id=
<TABLE id=
<TR>
<TD><asp:datagrid id=
<Columns>
<asp:BoundColumn HeaderText=
<asp:TemplateColumn HeaderText=
<asp:TemplateColumn HeaderText=
<ItemTemplate>
<asp:Label ID=
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText=
<ItemTemplate>
<%# (DataGrid
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText=
<ItemTemplate>
<%# GetRecordIndex( Container
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField=
</Columns>
<PagerStyle Mode=
</asp:datagrid></TD>
</TR>
<TR>
<TD></TD>
</TR>
<TR>
<TD></TD>
</TR>
</TABLE>
</form>
</body>
</HTML>
後台WebFormPaging
using System;
using System
using System
using System
using System
using System
using System
using System
using System
using System
namespace AspnetPaging
{
public class WebForm
{
private int recordCount =
protected System
private void Page_Load(object sender
{
if(!Page
{
DataGridDataBind();
}
}
//綁定數據
private void DataGridDataBind()
{
DataSet ds = DataAccess
this
this
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base
}
/// <summary>
/// 設計器支持所需的方法
/// 此方法的內容
/// </summary>
private void InitializeComponent()
{
this
this
this
this
}
#endregion
//翻頁
private void DataGrid
{
DataGrid
DataGridDataBind();
}
//獲取當前項
protected int GetRecordIndex(int itemIndex)
{
return (DataGrid
}
private void DataGrid
{
DataGrid dg = (DataGrid)sender;
if(e
{
e
e
}
}
private void DataGrid
{
DataGrid dg = (DataGrid)sender;
if(e
{
((Label)e
}
}
}
數據層代碼如下
using System;
using System
using System
using System
namespace AspnetPaging
{
public class DataAccess
{
private static string connString = ConfigurationSettings
private DataAccess()
{
}
public static DataSet GetCustomersData()
{
SqlConnection conn = new SqlConnection(connString);
SqlCommand comm = new SqlCommand(
comm
SqlDataAdapter dataAdapter = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
dataAdapter
return ds;
}
}
}
總結
From:http://tw.wingwit.com/Article/program/net/201311/12926.html