Searching Through A GridView in ASP
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.
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:
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.