| | |
filter on gridview
Please support our ASP.NET advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 115
Reputation:
Solved Threads: 6
While i thought this would be really simple im really struggling on filtering a gridview twice!
I can bind data to my gridview on the choice of my first dropdown box from a dataset
but i would like to then filter those results from a selection in a second dropdown box but for the life of me i cant get it to work!
I can bind data to my gridview on the choice of my first dropdown box from a dataset
but i would like to then filter those results from a selection in a second dropdown box but for the life of me i cant get it to work!
ASP.NET Syntax (Toggle Plain Text)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If IsPostBack Then Me.drpDecision.Items.Clear() Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~") & "\App_Data\referrals.mdb;") Dim sql As String = "SELECT * FROM tbl_ WHERE RefService = '" & Me.drpCriteria.SelectedValue & "'" 'Dim SQL As String = "SELECT * FROM tbl_Service WHERE RefService LIKE '" & Me.drpCriteria.SelectedValue & "'" Dim da As New OleDbDataAdapter(sql, conn) Dim ds As New DataSet da.Fill(ds) GridView1.DataSource = ds GridView1.DataBind() MsgBox("Selection") Dim sql2 As String = "select Distinct(RefDecision) FROM tbl_Service WHERE RefService = '" & Me.drpCriteria.SelectedValue & "'" Dim da2 As New OleDbDataAdapter(sql2, conn) Dim ds2 As New DataSet Dim i As Integer da2.Fill(ds2) If ds2.Tables(0).Rows.Count > 0 Then For i = 0 To ds2.Tables(0).Rows.Count - 1 Me.drpDecision.Items.Add(ds2.Tables(0).Rows(i).Item(0)) Next Else Me.drpDecision.Items.Add("No matching records") End If If Me.drpDecision.SelectedValue <> "" Then MsgBox("Selection") FilterSearch(ds) End If End If End Sub Private Sub FilterSearch(ByRef ds As DataSet) GridView1.Dispose() Dim SearchTB As DataTable = ds.Tables(0) Dim Rows As DataRow() = SearchTB.Select("RefDecision = " & Me.drpDecision.SelectedValue) MsgBox(SearchTB.Rows.Count) GridView1.DataSource = SearchTB.DataSet GridView1.DataBind() End Sub
Please mark this post as 'Solved' if it has helped and fixed your issue.
•
•
Join Date: May 2009
Posts: 11
Reputation:
Solved Threads: 0
Hi ninj
First of all, put your data bind logic in a separate sub not in the page load event you will be needing it again.
Next call the new sub from the page load to make sure it works,
In the designer, double click the second dropdown box - it should take you to the OnSelectionChanged sub in the code behind- enter the name of the sub you created above.
If this does not work correctly it's probably because you are not storing the original value in the session object.
First of all, put your data bind logic in a separate sub not in the page load event you will be needing it again.
Next call the new sub from the page load to make sure it works,
In the designer, double click the second dropdown box - it should take you to the OnSelectionChanged sub in the code behind- enter the name of the sub you created above.
If this does not work correctly it's probably because you are not storing the original value in the session object.
![]() |
Similar Threads
- fixing <asp:gridview> header row and selecting rows at client side (ASP.NET)
- WHERE clause in vwd 2005 express (ASP.NET)
- Filtering a GridView by A Name and Two Dates (VB.NET)
- asp.net datagridview - searching for two values (ASP.NET)
- Filter DataSource before presente data in gridview (VB.NET)
- GridView in ASPX (C#)
- HyperLink MouseOver (ASP.NET)
- Populating Textbox with Gridview (VB.NET)
- C# .NET Gridview (C#)
- HELP Sorting SQL Database Data (VB.NET)
Other Threads in the ASP.NET Forum
Views: 2130 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 activexcontrol advice ajax alltypeofvideos anathor application asp asp.net bc30451 bottomasp.net box browser button c# checkbox commonfunctions complex connection dataaccesslayer database datagridview datagridviewcheckbox datalist development dgv dropdownlist dynamically edit editing expose feedback fileuploader fill flash form formatdecimal formview google gridview gudi iframe iis javascript list listbox login microsoft migration mono mouse mssql news numerical opera panelmasterpagebuttoncontrols parent problem project radio redirect registration relationaldatabases reportemail richtextbox rows save schoolproject search security select services session silverlight smartcard smoobjects software sql sql-server sqlserver2005 suse textbox theft tracking unauthorized validation vb.net video videos view vista visualstudio web webapplications webdevelopemnt webprogramming webservice xsl youareanotmemberofthedebuggerusers





