p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   Refreshing a Gridview (http://p2p.wrox.com/showthread.php?t=65082)

takwirira January 7th, 2008 01:42 PM

Refreshing a Gridview
I have the code below it searches a database using the SQL LIKE command and populates a gridview. The only problem is when I search once I cant search again unless I reload the page. Is there a way I can close and reopen the connection or refresh so that I can enter text to search again.

Imports System.Data
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

' create a connection string
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("runnersdb.mdb")
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
' create a data adapter
'Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Runners", myConnection)
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Runners WHERE Name LIKE '%" & txtName.Text & "%'", myConnection)

' create a new dataset
Dim ds As DataSet = New DataSet
' fill dataset

da.Fill(ds, "Runners")
' Attach DataSet to DataGrid

GridView1.DataSourceID() = ""
GridView1.DataSource = ds.Tables(0).DefaultView

End Sub

End Class

stupid January 9th, 2008 01:13 AM

This requires a postback, and unless you are using the ASP.NET AJAX extensions (easy) or write a custom Javascript call (hard) you will have to have a full page refresh.

I highly recommend the AJAX extension provided by microsoft. You could make this happen easily with just a few extra lines of code.
Link: http://asp.net/ajax/

All times are GMT -4. The time now is 06:22 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.