Getting DataRepeater control to work without binding EVERY time

J

jaffarkazi

Hi all,
I'm developing a site. One of the features is a search page, for which
I'm using a data repeater control.

For the rest of the pages it is fine, but, obviously, on the search
page, for the first time, there will be no search results. Only when
the user specifies his search parameters will the search show up.

The Page_Load event for the search control looks as follows:
protected void Page_Load(object sender, EventArgs e)
{
DataBind();

if (!IsPostBack)
{
LoadDefinedData();

DoSearch();
}
DoSearch();
}

and other methods are:

protected void btnSearch_Click(object sender, EventArgs e)
{
DoSearch();
}

private void DoSearch()
{
...prepare params
if (csi.Search(params))
{

Repeater.DataSource = csi.DefaultView;
Repeater.DataBind();
}
}

So I'm having to hit the database TWICE for each request. If I remove
the 2nd DoSearch from the Page_Load, then no data shows up, and I
actually want to remove both the DoSearch()es from the Page_load, and
just rely on the Search_Click DoSearch.

How can I achieve this? I've gone MAD trying to get this stupid
straight forward thing to work, and I need to put it into production
as soon as possible.

Thanks in advance, and all help appreciated.

Regards,
--Jaffar
 
J

Joe

Maybe I'm making this too simple. You said on the inital load of the
search page there would be no results. Then once they search the
results should show.

Remove all the code from the page_load you have shown. Put the
DoSearch() function in the button click event. Make sure you finish
by binding the data to your repeater.

-joe
 
J

jaffarkazi

No, the problem is that my problem SOUNDS too simple. I did exactly
what you suggested before I posted this problem. If I remove any code
from the Page_Load which results in DataBinding, the search does not
work whenever I press the search button. I mean, the search works, but
the ItemCommand event does not fire on the repeater. Because of this,
the ID of the record does not get populated, and I cannot view the
details, when I press the button present in the DataRepeater.

Thanks for your time. And sorry for not being so clear the first time.

Regards,
--Jaffar
 
M

Munna

No, the problem is that my problem SOUNDS too simple. I did exactly
what you suggested before I posted this problem. If I remove any code
from the Page_Load which results in DataBinding, the search does not
work whenever I press the search button. I mean, the search works, but
the ItemCommand event does not fire on the repeater. Because of this,
the ID of the record does not get populated, and I cannot view the
details, when I press the button present in the DataRepeater.

Thanks for your time. And sorry for not being so clear the first time.

Regards,
--Jaffar

Hi

Try Remove the Page's DataBind() method invocation at the top of the
page...

First of all there should not be any code in the page_load event of
your scenario , thing are pretty simple in your case...
1. Get the search option from somewhere (where from the search query
come from by the way?)
2. Execute the search ...
3. Get the result
4. bind it to result grid and save the result in session or somewhere
else to use it for later use.

In your case


if (!IsPostBack)
{
LoadDefinedData();

DoSearch(); //this code is useless
}
DoSearch(); //since this will be execute any way...

please investigate your search binding scenario...

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
 
G

gerry

is it enabled on all containers as well ? ie usercontrol , page ... have
you posted an actual example of this problem somewhere ?
 
J

jaffarkazi

No, not posted it anywhere.
I've found a workaround/temporary solution/whatever you call it.

Earlier I was using buttons to go to the details page from search. Now
I'm using URLs, with the ID being passed as part of the URL.

Now, the code which was actually wrong, i.e., SearchData in Page_Load
has been correctly removed, and it works properly.

Thanks everyone for your time.

Regards,
--jaffar
 

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

Forum statistics

Threads
473,780
Messages
2,569,607
Members
45,241
Latest member
Lisa1997

Latest Threads

Top