利用RowFilter属性,将一个DataSet绑定到两个DataGrid

类别:.NET开发 点击:0 评论:0 推荐:
利用RowFilter属性,将一个DataSet绑定到两个DataGrid
作者:孟宪会 出自:【孟宪会之精彩世界】 发布日期:2003年5月15日 8点22分10秒

下面就是利用RowFilter属性,将一个DataSet绑定到两个DataGrid的例子代码:

<%@ Page Language="VB" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <script runat="server"> Sub Page_Load(Sender As Object, E As EventArgs) Dim myConnection As New SqlConnection("server=.;uid=sa;pwd=;database=pubs") Dim myAdapter As New SqlDataAdapter("SELECT au_fname,phone,contract FROM Authors", myConnection) Dim myDataSet As New DataSet() Try myAdapter.Fill(myDataSet, "Test1") Dim myDataView As DataView = myDataSet.Tables("Test1").DefaultView myDataView.RowFilter = "contract=false" myFemaleDataGrid.DataSource = myDataView myFemaleDataGrid.DataBind() myDataView.RowFilter = "contract=true" myMaleDataGrid.DataSource = myDataView myMaleDataGrid.DataBind() Catch myException As Exception Response.Write("错误: " & myException.ToString()) End Try End Sub </script> <html> <head> </head> <body> <form runat="server" ID="Form1"> <p> contract[False]:<br> <asp:datagrid id="myFemaleDataGrid" runat="server" autogeneratecolumns="false" enableviewstate="false"> <columns> <asp:templatecolumn headertext="Name"> <itemtemplate> <span><%# Container.DataItem("au_fname") %> <p>本文地址:http://com.8s8s.com/it/it43234.htm</p> </div> </div> </div> <div class="content_tag"> <script src="/js/module_astro_input.js" type="text/javascript"></script> </div> </div> <div class="tech_show"> <script type="text/javascript">module_love_728x90();</script> </div> <div class="tech_footer"> <p>Copyright &copy; 2004-2013 信息技术中文网 All rights reserved 版权所有</p> <p>Powered by 信息技术中文网 Ver2.0</p> </div> </div> <script type="text/javascript">module_footer();</script> </body> </html>