打印

[asp.net教程] 利用rowfilter属性,将一个dataset绑定到两个datagrid

利用rowfilter属性,将一个dataset绑定到两个datagrid

下面就是利用rowfilter属性,将一个dataset绑定到两个datagrid的例子代码:
   
  <%@ page language="<a href="http://dev.21tx.com/language/vb/" target="_blank">vb</a>" %>
  <%@ 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") %></span>
   </itemtemplate>
   </asp:templatecolumn>
   <asp:templatecolumn headertext="contract">
   <itemtemplate>
   <span><%# container.dataitem("contract") %></span>
   </itemtemplate>
   </asp:templatecolumn>
   <asp:templatecolumn headertext="phone">
   <itemtemplate>
   <span><%# container.dataitem("phone") %></span>
   </itemtemplate>
   </asp:templatecolumn>
   </columns>

   </asp:datagrid>
   </p>
   <p>
   contract[true]:<br>
   <asp:datagrid id="mymaledatagrid" runat="server" autogeneratecolumns="false" enableviewstate="false">
   <columns>
   <asp:templatecolumn headertext="name">
   <itemtemplate>
   <span><%# container.dataitem("au_fname") %></span>
   </itemtemplate>
   </asp:templatecolumn>
   <asp:templatecolumn headertext="contract">
   <itemtemplate>
   <span><%# container.dataitem("contract") %></span>
   </itemtemplate>
   </asp:templatecolumn>
   <asp:templatecolumn headertext="phone">
   <itemtemplate>
   <span><%# container.dataitem("phone") %></span>
   </itemtemplate>
   </asp:templatecolumn>
   </columns>
   </asp:datagrid>
   </p>
  </form>
  </body>
  </html>

TOP

返回顶部
AYBlue

Processed in 0.073363 second(s), 7 queries.

当前时区 GMT+8, 现在时间是 2009-1-10 11:19 京ICP备06054220号

清除 Cookies - 联系我们 - 163K.com - Archiver - WAP