GridView binding - how to stop initial binding

A

Amit

Hello,
I have a simple search screen, with two drop-downs and a text box. There's
also a GridView control that is using a SqlDataSource control to show the
matching results. The SqlDataSource uses the control values in its query as
parameters. Two questions:

1. When the Find button is clicked, how do I tell the GridView to load the
data?
2. How do I stop the GridView from data binding when the page first loads? I
don't want to pre-populate the grid, it should only show the data after the
Find button is clicked

Thanks
Amit
 
E

Eliyahu Goldin

Call myGrid.DataBind (); in the Find button OnClick event handler. This will
solve both problems.

Eliyahu
 
A

Amit

I tried that but it didn't load the grid. I kept the SQL Profiler running
and it didn't even send a database query.
-Amit
 
O

Otis Mukinfus

I tried that but it didn't load the grid. I kept the SQL Profiler running
and it didn't even send a database query.
-Amit

Amit,

If you want to populate the grid using the criteria from the drop downs you must
do it the way Eliyahu told you, but now you will have to call your
DatatAdapter's Fill method in the click event.

To prevent the grid from filling the first time you load the page, move the
DataAdapter's Fill method to the click event. That will keep it from loading on
the page load.

Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
A

Amit

Otis,
Thanks for your reply. I was using the SqlDataSource object bound to a
stored procedure to do the binding. But now it looks like I have to do the
binding myself, without using the SqlDataSource object.
Thanks
Amit
 
J

jurev

You can prevent initial GridView binding by setting GridView.Visible to
false by default, and setting to true in button OnClick event.

When GridView.Visible is set to false the DataSource select command
will not be executed.
 
Joined
Oct 24, 2006
Messages
1
Reaction score
0
You can bind on button click using the VS controls with the following code:

SqlDataSource1.DataBind();
GridView1.DataBind();

This rebinds your source first, then your gridview.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top