Wrox Programmer Forums
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 7th, 2008, 01:42 PM
Authorized User
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

Old January 9th, 2008, 01:13 AM
Registered User
Join Date: Jan 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

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/

Similar Threads
Thread Thread Starter Forum Replies Last Post
Get GridView Cell Value Based on GridView Column stublair C# 2008 aka C# 3.0 0 September 4th, 2008 08:30 AM
page not refreshing Bill Crawley ASP.NET 2.0 Basics 8 February 28th, 2007 11:39 AM
img not refreshing austinf XSLT 1 June 13th, 2006 03:55 AM
refreshing XML withour refreshing the page sasidhar79 XML 1 January 12th, 2005 05:16 AM
Refreshing a sub-form from another sub-from lguzman Access VBA 1 November 29th, 2004 05:07 PM

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