Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a GridView based on a control value

Status
Not open for further replies.

JScannell

Programmer
Jan 9, 2001
306
US
I have a dropdown list that contains Job Numbers from a source table.
I have a GridView that lists all of the records from another table based on the JobNumber dropdown list value.

Problem:
The grid view only populates on page load. It contains records for the first job number in the dropdown list. So I know that the data binding is OK.

If I change the dropdown list value to another job Number, nothing happens to the gridview. Why?

Am I supposed to have an event tied to the dropdown change? If so, then how do you code it?

Thanks in advance,



Jerry Scannell
 
PS. A little something that I accidentally discovered:
The GridView is setup to "Enable Paging" so I get a 1 2 3... at the bottom of the GridView for large datasets.

In that situation, if I change the Job number, and then click on the 2, 3, ..., the gridView re-populates like it should, WITH the new job number's data!

So the question is "What do I have to do to make the GridView re-populate as soon as I change the DropDown selection?


Jerry Scannell
 
You have to set the dropdownlist to trigger a postback when it is changed. This is a property you can set.
You also have to create and code the selectedindexchanged event of the dropdownlist. In there you get the id, run your sql, and bind your grid.
I would not have the grid bind on page_load for the first ddl value.
A quick example of what I would do.
Page Load:
If not page.ispostback then
get data for ddl and bind
'Have the first value be something like "<Select Job Number>"
end if

selected index changed event of ddl:
eg. GetData()

sub GetData()
get data for grid and bind based on ddl value


 
jbenson1,

Thanks for the quick reply. It seems that all I needed to do was set the postback property to true. The other ideas you mentioned weren't needed.

Thanks,

Jerry Scannell
 
paging data from the gridview control is the performance nightmare waiting to happen.
1. paging is done in code instead of at the database level
2. the entire result set is stored in viewstate

even with a few hundred rows the page will begin to take a hit. 1000s+ will crash the app.

alter your code to page the data at the database, not the UI and you can avoid these problems before they start.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top