在Gridview中过滤 [英] Filter in Gridview

查看:75
本文介绍了在Gridview中过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨那里有


我有一个gridview(myGridview)(按下按钮时显示正常)并且需要像上面那样使用文本框过滤它(txtRegionFilter )作为输入。我已经在底部添加了红色的部分,但它不起作用并给我一个错误"myGridviewBindingSource
是主页面的一部分"在部分:Me.myGridviewBindingSource.Filter。我的代码看起来如下可以帮助你:

Hi There

I have a gridview (myGridview) (it displays fine on hitting the button) and needs to filter it like the above using a textbox (txtRegionFilter) as input. Ihave added the portion in red at the bottom but it is not working and give me an error "myGridviewBindingSource is part of the main page" on the portion: Me.myGridviewBindingSource.Filter . My code looks as follow can you assist please:


Imports System.Data

Partial Class MainPage
    Inherits System.Web.UI.Page


    Protected Sub btnLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoad.Click
        Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\vaardtlc\Documents\Info\Webdesign\Link Assistance\AddressBook.mdb"
        Dim SQLString As String = "SELECT * FROM tblContacts"
        Dim OleDBConn1 As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(ConnString)
        Dim dataset1 As New DataSet
        Dim OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, OleDBConn1)

        OleDBConn1.Open()
        OleDbDataAdapter1.Fill(DataSet1, "Addressbook")
        myGridview.DataSource = dataset1.Tables("Addressbook")
        myGridview.DataBind()

        Dim RegionFilter As String
        'Accept user input
        RegionFilter = txtRegionFilter.Text

        txtTestOutput.Text = RegionFilter

        Dim txt As String = txtRegionFilter.Text
        If String.IsNullOrEmpty(txt) Then
            Me.myGridviewBindingSource.RemoveFilter()
        Else
            Me.myGridviewBindingSource.Filter = "Region Like '" & txt & "%'"
        End If

     The red portion did not come out, it is from the last dim to the end if....


    End Sub

End Class

推荐答案

您正在BindingSource上设置过滤器,但看起来您的gridview未绑定到BindingSource。 您的代码将其DataSource设置为dataset1.Tables(" Addressbook")

Well you are setting the filter on a BindingSource but it appears your gridview isn't bound to the BindingSource.  Your code sets its DataSource to dataset1.Tables("Addressbook")


这篇关于在Gridview中过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆