Getting DataRepeater control to work without binding EVERY time

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jaffarkazi

    #1

    Getting DataRepeater control to work without binding EVERY time

    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(objec t 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(par ams))
    {

    Repeater.DataSo urce = csi.DefaultView ;
    Repeater.DataBi nd();
    }
    }

    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
  • Joe

    #2
    Re: Getting DataRepeater control to work without binding EVERY time

    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

    Comment

    • jaffarkazi

      #3
      Re: Getting DataRepeater control to work without binding EVERY time

      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

      Comment

      • Munna

        #4
        Re: Getting DataRepeater control to work without binding EVERY time

        On Jun 3, 2:00 pm, jaffarkazi <jaffar.k...@gm ail.comwrote:
        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



        Comment

        • gerry

          #5
          Re: Getting DataRepeater control to work without binding EVERY time

          sounds like you have viewstate disabled on the repeater


          "jaffarkazi " <jaffar.kazi@gm ail.comwrote in message
          news:1bf7edcd-51ab-4b00-9842-59bfc58cfcd1@p3 9g2000prm.googl egroups.com...
          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

          Comment

          • jaffarkazi

            #6
            Re: Getting DataRepeater control to work without binding EVERY time

            On Jun 3, 4:10 pm, "gerry" <g...@newsgroup .nospamwrote:
            sounds like you have viewstate disabled on the repeater
            >
            "jaffarkazi " <jaffar.k...@gm ail.comwrote in message
            >
            news:1bf7edcd-51ab-4b00-9842-59bfc58cfcd1@p3 9g2000prm.googl egroups.com...
            >
            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
            Tried enabling that too! :) No solution.

            Comment

            • gerry

              #7
              Re: Getting DataRepeater control to work without binding EVERY time

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


              "jaffarkazi " <jaffar.kazi@gm ail.comwrote in message
              news:638c03eb-5c3c-4690-833e-78f3f482cd90@56 g2000hsm.google groups.com...
              On Jun 3, 4:10 pm, "gerry" <g...@newsgroup .nospamwrote:
              >sounds like you have viewstate disabled on the repeater
              >>
              >"jaffarkazi " <jaffar.k...@gm ail.comwrote in message
              >>
              >news:1bf7edc d-51ab-4b00-9842-59bfc58cfcd1@p3 9g2000prm.googl egroups.com...
              >>
              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
              >
              Tried enabling that too! :) No solution.

              Comment

              • jaffarkazi

                #8
                Re: Getting DataRepeater control to work without binding EVERY time

                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

                Comment

                Working...