可以通过绑定的DATASET。
以下的例子可以参考。
<%@ Page Language="C#"
Debug="true"
%>
<script runat="server">
protected void Page_Load( object sender, EventArgs e )
{
System.Data.DataView dv = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
Response.Write(dv.Count.Tostring());
}
protected void CustomersGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Data.DataRowView dv = (System.Data.DataRowView)e.Row.DataItem;
Response.Write("<li>"
+ dv.Row["Address"].Tostring());
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title></title></head>
<body>
<form id="Form1"
runat="server">
<asp:GridView ID="CustomersGridView"
DataSourceID="SqlDataSource1"
AllowPaging="True"
SelectedIndex="0"
runat="server"
OnRowDataBound="CustomersGridView_RowDataBound">
</asp:GridView>
<br />
<asp:Label ID="Message"
ForeColor="Red"
runat="server"
/>
<asp:SqlDataSource ID="SqlDataSource1"
SelectCommand="SELECT [CustomerID], [CompanyName], [Address] FROM [Customers]"
ConnectionString="Server=(local);Database=Northwind;Trusted_Connection=True;"
runat="server"
DataSourceMode="DataSet"
/>
</form>
</body>
</html>