GridView binding - how to stop initial binding

Discussion in 'ASP .Net' started by Amit, Apr 29, 2006.

  1. Amit

    Amit Guest

    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
    Amit, Apr 29, 2006
    #1
    1. Advertising

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

    Eliyahu

    "Amit" <> wrote in message
    news:u%...
    > 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
    >
    >
    Eliyahu Goldin, Apr 30, 2006
    #2
    1. Advertising

  3. Amit

    Amit Guest

    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



    "Eliyahu Goldin" <> wrote in message
    news:...
    > Call myGrid.DataBind (); in the Find button OnClick event handler. This
    > will solve both problems.
    >
    > Eliyahu
    >
    > "Amit" <> wrote in message
    > news:u%...
    >> 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
    >>
    >>

    >
    >
    Amit, Apr 30, 2006
    #3
  4. On Sun, 30 Apr 2006 14:29:59 -0400, "Amit" <> wrote:

    >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
    >
    >
    >
    >"Eliyahu Goldin" <> wrote in message
    >news:...
    >> Call myGrid.DataBind (); in the Find button OnClick event handler. This
    >> will solve both problems.
    >>
    >> Eliyahu
    >>
    >> "Amit" <> wrote in message
    >> news:u%...
    >>> 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
    >>>
    >>>

    >>
    >>

    >


    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
    Otis Mukinfus, Apr 30, 2006
    #4
  5. Amit

    Amit Guest

    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


    "Otis Mukinfus" <> wrote in message
    news:...
    > 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
    Amit, May 1, 2006
    #5
  6. Amit

    jurev Guest

    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.

    Amit wrote:
    > 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
    jurev, May 10, 2006
    #6
  7. Amit

    Assimalyst

    Joined:
    Oct 24, 2006
    Messages:
    1
    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
    Assimalyst, Oct 24, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Theule

    Stop Debugging doesn't stop in ASP.NET

    Matt Theule, Jul 23, 2003, in forum: ASP .Net
    Replies:
    7
    Views:
    733
    Matt Theule
    Jul 24, 2003
  2. Son KwonNam
    Replies:
    11
    Views:
    2,601
    mr_organic
    Apr 9, 2004
  3. Will
    Replies:
    1
    Views:
    15,233
    Thomas Weidenfeller
    Nov 2, 2004
  4. Angus
    Replies:
    5
    Views:
    451
    Ben Bacarisse
    Jul 18, 2010
  5. Replies:
    4
    Views:
    311
Loading...

Share This Page