在ASP.Net中怎样取得sqldatasource某个字段的值? ( 积分: 100 )

  • 主题发起人 主题发起人 DF7C3
  • 开始时间 开始时间
可以通过绑定的DATASET。
以下的例子可以参考。
<%@ Page Language=&quot;C#&quot;
Debug=&quot;true&quot;
%>
<script runat=&quot;server&quot;>
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(&quot;<li>&quot;
+ dv.Row[&quot;Address&quot;].Tostring());
}
}
</script>
<html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;>
<head><title></title></head>
<body>
<form id=&quot;Form1&quot;
runat=&quot;server&quot;>
<asp:GridView ID=&quot;CustomersGridView&quot;
DataSourceID=&quot;SqlDataSource1&quot;
AllowPaging=&quot;True&quot;
SelectedIndex=&quot;0&quot;
runat=&quot;server&quot;
OnRowDataBound=&quot;CustomersGridView_RowDataBound&quot;>
</asp:GridView>
<br />
<asp:Label ID=&quot;Message&quot;
ForeColor=&quot;Red&quot;
runat=&quot;server&quot;
/>
<asp:SqlDataSource ID=&quot;SqlDataSource1&quot;
SelectCommand=&quot;SELECT [CustomerID], [CompanyName], [Address] FROM [Customers]&quot;
ConnectionString=&quot;Server=(local);Database=Northwind;Trusted_Connection=True;&quot;
runat=&quot;server&quot;
DataSourceMode=&quot;DataSet&quot;
/>
</form>
</body>
</html>
 
接受答案了.
 
后退
顶部