我有一个gridview,从Web服务获取其数据.
这进入了数据集中的应用程序.
Me.GvStreets.DataSource = TheWebServiceSearch.AddressDataTable Me.GvStreets.DataBind()
进入网格视图后,如何搜索此数据集的内容.
我是否必须将其添加到某种数据源控件(如XML数据源)中?
谢谢
我最终做的是这个......
Dim StreetDataTable As DataTable = Session("StreetData") Dim Name As String = StreetDataTable.Columns(0).ColumnName Dim FilteredResults As New DataTable FilteredResults = StreetDataTable.Clone() Dim DataRows() As DataRow DataRows = StreetDataTable.Select("street LIKE '%" & Me.txtStreet.Text & _ "%'", "Street ASC") Dim i As Integer For i = 0 To DataRows.GetUpperBound(0) FilteredResults.ImportRow(DataRows(i)) Next i Me.GvStreets.DataSource = FilteredResults Me.GvStreets.DataBind()
我必须得到结果并克隆数据表以获得架构.然后我从原始数据表中做了选择.我循环查看结果并将它们添加到克隆数据表中.
通常,您将直接搜索数据源,因此在您的情况下,因为TheWebServiceSearch.AddressDataTable是DataTable,您可以执行以下操作:
DataTable data = TheWebServiceSearch.AddressDataTable; DataRow[] foundRows = data.Select("city = 'NY'", "zip ASC");
您可以在此处查看 DataTable.Select重载的完整列表
哦,好吧,现在我明白了你需要什么.我以为你想要别的东西.无论如何,你应该使用DataView对象(也是可绑定的).这是一个例子:
Dim StreetDataTable As DataTable = Session("StreetData") Dim Name As String = StreetDataTable.Columns(0).ColumnName StreetDataTable.DefaultView.RowFilter = "street LIKE '%" & Me.txtStreet.Text & "%'" StreetDataTable.DefaultView.Sort = "Street ASC" Me.GvStreets.DataSource = StreetDataTable.DefaultView Me.GvStreets.DataBind()
看看DataView的完整规范.