Solved

Binding a DropDownList to a GridView

Posted on 2009-04-05
7
402 Views
Last Modified: 2012-05-06
Experts,

I have a grid view that's tied to a database table.  One of the fields is Product_Category.  I want to select a value for that field from a DropDownList and filter the grid accordingly.  How do I do that?
0
Comment
Question by:NigelRocks
  • 4
  • 3
7 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24072589
0
 
LVL 1

Author Comment

by:NigelRocks
ID: 24072604
That's not quite what I'm looking for.  I want to use a DropDownlist OUTSIDE the grid to filter the contents of the grid.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24072626
ok, I see.

you put the dropdownlist, and put the usual code to fill this list from the data source (dataset/datareader) as you need on the first page_load...

ensure the dropdown is "autopostback", and on the selection change event, you will have to run the code to re-query or only re-bind the data grid. the choice depends on how much data you have if unfiltered, and how much time the query for unfiltered/filtered takes.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Author Comment

by:NigelRocks
ID: 24072714
I'm assuming I re-query against the DataSource of the GridView.  How do I do that?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24072752
how do you run the data source initially?
0
 
LVL 1

Author Comment

by:NigelRocks
ID: 24072785
I have a dropdownlist bound to a table datasource and a gridview bound to a table source.  I run them by hitting "click".
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24072820
can you show the relevant code that you use to query?
in there, you have to use the dropdown's selecteditem property (if != null), to use for example the value, to build the query...
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question