How to change data in grid after you change the SQL select for the data adapter

Discussion in 'ASP .Net Datagrid Control' started by tom c, Jun 6, 2006.

  1. tom c

    tom c Guest

    I have an ASP.net webform with a datagrid on it.

    I can change the SQL select statement for the grid in code by putting
    a statement like this in the first line of Page_Load
    OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
    where ... "

    The rest of the code in Sub Page_Load is

    OleDbDataAdapter1.Fill(DsCategories1)
    If Not IsPostBack Then
    DataGrid1.DataBind()
    End If

    This works fine on the initial load of the the webform. If I want to
    change the SQL command to load different data into the grid after the
    form is loaded, and do that with a cmdButton, what code to I put under
    the cmdButton to reload the webform or grid with the new sql select?
     
    tom c, Jun 6, 2006
    #1
    1. Advertising

  2. tom c

    PeterKellner Guest

    On 5 Jun 2006 19:15:20 -0700, "tom c" <> wrote:

    >I have an ASP.net webform with a datagrid on it.
    >
    >I can change the SQL select statement for the grid in code by putting
    >a statement like this in the first line of Page_Load
    >OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
    >where ... "
    >
    >The rest of the code in Sub Page_Load is
    >
    > OleDbDataAdapter1.Fill(DsCategories1)
    > If Not IsPostBack Then
    > DataGrid1.DataBind()
    > End If
    >
    >This works fine on the initial load of the the webform. If I want to
    >change the SQL command to load different data into the grid after the
    >form is loaded, and do that with a cmdButton, what code to I put under
    >the cmdButton to reload the webform or grid with the new sql select?


    You would call DataBind() on your datagrid. This rexecutes the get
    code in your bound datasource.
    Peter Kellner
    http://peterkellner.net
     
    PeterKellner, Jun 8, 2006
    #2
    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. Andrew
    Replies:
    1
    Views:
    1,228
    Hermit Dave
    Jan 26, 2004
  2. Goober at  christianDOTnet

    Datagrid, SQL Adapter question

    Goober at christianDOTnet, Jul 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    513
    Eliyahu Goldin
    Jul 11, 2004
  3. Randy Smith
    Replies:
    0
    Views:
    441
    Randy Smith
    Apr 28, 2005
  4. ocean
    Replies:
    0
    Views:
    386
    ocean
    Mar 13, 2006
  5. ocean
    Replies:
    1
    Views:
    538
    =?Utf-8?B?RFdT?=
    Mar 15, 2006
Loading...

Share This Page