0% found this document useful (0 votes)
25 views

Searching Through A GridView in ASP

The document discusses adding search functionality to a GridView in an ASP.NET application to allow searching through products. It provides steps to add a label, textbox and button for search, configure the GridView to connect to a database and include search criteria in the query, and style the GridView columns.

Uploaded by

Abby P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Searching Through A GridView in ASP

The document discusses adding search functionality to a GridView in an ASP.NET application to allow searching through products. It provides steps to add a label, textbox and button for search, configure the GridView to connect to a database and include search criteria in the query, and style the GridView columns.

Uploaded by

Abby P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Searching through a GridView in ASP.

NET
Now that we have a functional “portal” that is able to authenticate a user’s role from a database, let’s add some
content. In this first lesson we will be adding a Product GridView that the user will be able to search through.

To start, create a new web form with master page called “Products.aspx” and add the following code:

Before running your application, make sure you add the NavigateURL to this page in the Site2.Master so you will be able
to go there.

From here we will start adding our content. First, add a label, textbox, and button to our page. This will be for our search
functionality.

Next, add a GridView:


Then to configure it, just like we have done in the past to our FormView, we will go to our design view and add a new
data source called dsProducts.

Connect to your Users connection string and configure your query according to the following:

The WHERE clause is how we will make our textbox talk to our GV.
Once finished, click on the GridView again and enable the following:

From here, we will choose “Edit columns” and configure your data grid view to look like the following:

You will need to give the columns more “user friendly” header text and reorder them. From there I recommend either
styling them in the same pane, or choosing the auto format option at the very top of the GridView tasks.

For the button, we are going to want the user to be able to edit/update the product, so we will change the select
button’s properties to the following:
Once finished, should look something like this, or styled slightly differently:

Now, it’s time to test out our search functionality:

One user experience thing I ran into was the fact that after typing something into the textbox and hitting enter, it logged
me out of the account and since we disabled the back button, I was unable to go back. To fix this, I went to my logout
button in the site2.master and set this property:

The UseSubmitBehavior property to specify whether a Button control uses the client browser's submit mechanism
(Enter). By default, the value of this property is true.

In the next lesson, we will configure the update button in the gridview.

You might also like