Datagrid question

Discussion in 'ASP .Net Web Controls' started by Sanjay, Jun 2, 2004.

  1. Sanjay

    Sanjay Guest

    I am a newbie. On a button click, I use the following databind for a
    datagrid that works perfectly. But after that, no matter which page
    number I click at the bottom, I always get the first page. The same
    happens with the column header clicks to sort, reverse-sort, etc. How
    can I fix this? Thanks.

    void btEntry_Click(object sender, EventArgs e) {

    dataSrc.SelectCommand = "SELECT * FROM [visits] where
    visitedPage like @anStr";

    dataSrc.Parameters.Clear();

    dataSrc.Parameters.Add("@anStr", srchBox.Text);

    dataGrid.DataBind();

    }
     
    Sanjay, Jun 2, 2004
    #1
    1. Advertising

  2. Sanjay

    ranganh Guest

    Hi

    Did you write the OnPageIndexChanged functionality

    the place where you declare the datagrid, include the following attribute OnPageIndexChanged="dataGrid_PageIndexChanged" and then you have to write the following in your code behin

    public void dataGrid_PageIndexChanged(object s, DataGridPageChangedEventArgs e) //Function for paging


    dataGrid.CurrentPageIndex = e.NewPageIndex
    BindData()
     
    ranganh, Jun 2, 2004
    #2
    1. Advertising

  3. Sanjay

    winenthu Guest

    Sorry, I didn't mention that it is an mxdatagrid and I am using
    webmatrix. Usually this control does an auto paging, sorting, etc. Only
    when I put the AutoDataBind off and then manually bind data, the paging
    features are broken. The code that you gave does not fix this.

    The problem is I don't know the whole picture of how this control works,
    and any books that I have read fail to give the advanced usage. If I
    have changed the data source with a new select statement and now the
    mxdatagrid is using that data source, how to get it to do autopaging,
    etc for the new data?

    Thanks.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    winenthu, Jun 2, 2004
    #3
  4. Sanjay

    winenthu Guest

    I finally solved this problem by the following code modification (note
    that this is mxdatagrid and not datagrid):

    <code>
    void Page_Load(Object sender, EventArgs E ) {
    if (IsPostBack) {
    dataGrid.AutoDataBind = true;
    dataGrid.DataBind();
    }
    }

    void btEntry_Click(object sender, EventArgs e) {
    dataGrid.AutoDataBind = false;
    dataSrc.SelectCommand = "SELECT * FROM [visits] where
    visitedPage like @anStr";
    dataSrc.Parameters.Clear();
    dataSrc.Parameters.Add("@anStr", srchBox.Text);
    dataGrid.DataBind();
    }
    </code>

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    winenthu, Jun 2, 2004
    #4
    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. Dave
    Replies:
    0
    Views:
    456
  2. BK Kim

    datagrid in datagrid

    BK Kim, Feb 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    550
    Alvin Bruney [MVP]
    Mar 2, 2004
  3. =?Utf-8?B?U3VyZXNo?=
    Replies:
    0
    Views:
    528
    =?Utf-8?B?U3VyZXNo?=
    Mar 2, 2004
  4. Brian K. Williams
    Replies:
    0
    Views:
    548
    Brian K. Williams
    Mar 2, 2004
  5. Andreas Klemt
    Replies:
    0
    Views:
    313
    Andreas Klemt
    Oct 8, 2003
Loading...

Share This Page