Groups | Blog | Home
all groups > inetserver asp db > september 2006 >

inetserver asp db : filtering DataGrid on the fly


michael sorens
9/27/2006 2:14:31 PM

I am well-versed in Windows Forms but am new to Web Forms with ASP.NET. I
want to create a simple application that loads all rows of a SQLServer
table into a DataGrid, then allow the user to filter the rows on-the-fly
via entry in a TextBox. I have done this in a WinForm application by
setting the BindingSource.Filter property to an appropriate 'where' clause
and by capturing the changed property I am able to dynamically filter the
rows with each keystroke. Can this be done in a WebForm application? (If
michael sorens
9/27/2006 4:02:42 PM
Some exploration led me to the SelectCommand and the FilterExpression
properties of the SqlDataSource which may be used to do filtering
vai the submit-button-model. I am still hoping for suggestions on how to
act upon a keystroke; could this be done? And could it be done without a
round-trip to the server, i.e. just filter the results locally?


On Wed, 27 Sep 2006 14:14:31 -0700, michael sorens
[quoted text, click to view]
I am well-versed in Windows Forms but am new to Web Forms with ASP.NET. I
want to create a simple application that loads all rows of a SQLServer
table into a DataGrid, then allow the user to filter the rows on-the-fly
via entry in a TextBox. I have done this in a WinForm application by
setting the BindingSource.Filter property to an appropriate 'where' clause
and by capturing the changed property I am able to dynamically filter the
rows with each keystroke. Can this be done in a WebForm application? (If
stcheng NO[at]SPAM online.microsoft.com
9/28/2006 12:00:00 AM
Hello Michael,

From your description, I understand you're developing an ASP.NET web page
which will display some data from database and you want to also add the
funcionality to allow user input some text on the page to filter the data
displayed on the page, correct?

As for this question, I think we need to start from the ASP.NET web page
programing's underlying model which is quite different from winform
application.

ASP.NET web application is page based and each time the user visit a page,
it will got through the following steps:

**user request the page in browser address bar(or invoke a certain link or
button on former page)

**browser send request to the server

**server receive the request and use the proper handler to process the
request

**ASP.NET runtime load the certain page class and go through the page's
server-side lifecycle include page initialization, page viewstate
processing, page event processing, page rendering .....

Here are two good msdn reference introducing the ASP.NET runtime lifecycle:

#ASP.NET Application Life Cycle Overview
http://msdn2.microsoft.com/en-us/library/ms178473.aspx

#ASP.NET Page Life Cycle Overview
http://msdn2.microsoft.com/en-us/library/ms178472.aspx


** after the page is processed at server-side, the ASP.NET runtime flush
the response content back to client browser and the client browser display
the page as html.


Therefore, you can see that ASP.NET page based application is much
different from winform. ASP.NET application is request/response based and
the server-side execution/processing only take a little period of time in
the whole lifecycle. While for winform, during the application's whole
lifetime, the application is executing in memory and the application data
and variables are accessible.


Then, for your scenario, you want to display data in ASP.NET page(I assmue
you're using ASP.NET 2.0), you need to use ASP.NET DataBound control on the
page and use ASP.NET databinding to bind data (from database ) to the
databound control. And in ASP.NET 2.0, the GridView is a good one to use,
it support bind data to DataTable/Dataview or our custom class
objects(list). And if you want to filter data, you need to regenerate the
filtered datasource(DataView) and rebind it to GridView. And if you want
to let the user to input the keyword for filtering, you can use a TextBox
(or dropdownlist) to display the filter options, and when the user input
some data and click a submit button, you'll regenerate the filtered data
according to the new input value (in textbox or dropdownlist) and bind the
new data to GridView. We can not do it on the fly like winform application
because ASP.NET application need to postback the page to server first and
then process the data in code.




Also, I suggest you have a look at the samples and tutorials in the
WWW.ASP.NET site since there're many good learning resource on ASP.NET
there. The following ones contains some example about data accessing in
asp.net and data filtering:


#ASP.NET Quickstart Tutorials--Performing Data Access
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/data/default.aspx


#Working with Data in ASP.NET 2.0
http://www.asp.net/learn/dataaccess/default.aspx?tabid=63


Also, the above info are some general guideline, if you have any detailed
questions or meet any specific problem when implementing the page, please
feel free to post here.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
Bob Barrows [MVP]
9/28/2006 8:25:31 AM
[quoted text, click to view]

There was no way for you to know it (except maybe by browsing through
some of the previous questions before posting yours - always a
recommended practice), but this is a classic asp newsgroup. ASP.Net is
a different technology from classic ASP. While you may be lucky enough
to find a dotnet-savvy person here who can answer your question, you
can eliminate the luck factor by posting your question to a newsgroup
where the dotnet-savvy people hang out. I suggest
microsoft.public.dotnet.framework.aspnet.
There are also forums at www.asp.net where you can find a lot of people

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

stcheng NO[at]SPAM online.microsoft.com
9/28/2006 1:21:49 PM
Thanks for Bob's advice,

Hi Michael,

I forgot to mention in my last reply that for pure ASP.NET questions you're
welcome to post in the following ASP.NET dedicated newsgroups:

microsoft.public.dotnet.framework.aspnet

microsoft.public.dotnet.framework.aspnet.buildingcontrols

microsoft.public.dotnet.framework.aspnet.caching

microsoft.public.dotnet.framework.aspnet.datagridcontrol

microsoft.public.dotnet.framework.aspnet.mobile

microsoft.public.dotnet.framework.aspnet.security

microsoft.public.dotnet.framework.aspnet.webcontrols

Or you can also post in the MSDN forum since there're also experienced
ASP.NET guys there:

http://forums.asp.net/

Hope this also helps.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.

AddThis Social Bookmark Button