GridView reorder problems

Discussion in 'ASP .Net' started by Kyle K., Oct 4, 2006.

  1. Kyle K.

    Kyle K. Guest

    (Note: Windows XP Pro SP2 + Visual Studio .NET 2005 + SQL Server 2000)

    I have a GridView that is populated with data. That last 2 columns are
    button fields (image buttons) that have a CommandName of "MoveUp" &
    "MoveDown" respectively. In the RowCreated event (for data rows only), I
    assign the CommandArgument the index of the current row so that I can
    retrieve the Key for the row from the DataKeys collection (in the
    RowCommand) event when one of the buttons are clicked.

    This key is then passed on to the Business-tier where it calls the
    proper Stored Procedure to move the record up/down. The Stored Procedure
    has been fully tested through Query Analyzer and works properly all the
    time, especially when providing it the data the application is passing
    in (as captured during debugging)

    However, when debugging (or running live) the code-path jumps around for
    unknown reasons. I'll be stepping through a series of sequential lines
    of code when the debugger will jump back a few lines and and either
    continue on from that point (re-executing statements that have already
    been executed) or jump forward again (either to the original line it
    jumped back from or forward), etc.

    This results in the record not moving at all or moving by 2 rows. I have
    rebuilt the website, rebooted my computer, etc. Sometime it works
    properly, but only on the first try. Subsequent tries always act strange.

    It appears like there are multiple threads running at the same time, but
    I am the only user and nobody outside of my machine is allowed access to
    the website.

    I have been trying to get to the bottom of this for some time now
    without success. Does anyone have any ideas how to proceed debugging this?

    ***** Code *****

    ASPX Code:

    protected void QResponseGridView_RowCreated( object sender,
    GridViewRowEventArgs e )
    {
    // only work on the 'data' rows
    if ( e.Row.RowType == DataControlRowType.DataRow )
    {
    // Up button
    ImageButton upButton =
    (ImageButton)e.Row.Cells[ 7 ].Controls[ 0 ];
    upButton.CommandArgument = e.Row.RowIndex.ToString();

    // hide if it's the first row
    if ( e.Row.RowIndex == 0 )
    upButton.Visible = false;


    // Down button
    ImageButton downButton =
    (ImageButton)e.Row.Cells[ 8 ].Controls[ 0 ];
    downButton.CommandArgument = e.Row.RowIndex.ToString();
    }// if
    }// QResponseGridView_RowCreated( sender, e )


    protected void QResponseGridView_RowCommand( object sender,
    GridViewCommandEventArgs e )
    {
    // 'move' requests
    if( e.CommandName == "MoveUp" || e.CommandName == "MoveDown" )
    {
    // create an instance of the QuestionResponses class
    QuestionResponses QResponsesBLL =
    new QuestionResponses();

    // get the current user performing the action
    string username = Membership.GetUser().UserName;

    // convert row index from CommandArgument to Integer
    int index = Convert.ToInt32( e.CommandArgument );

    // retrieve row containing the clicked button
    GridViewRow row = QResponseGridView.Rows[ index ];

    // get ID from hidden QuestionResponseID field
    int questionResponseID =
    Convert.ToInt32(
    QResponseGridView.DataKeys[
    row.DataItemIndex ].Value );

    // move response up/down
    if ( e.CommandName == "MoveUp" )
    QResponsesBLL.MoveResponseUp(
    questionResponseID, username );
    else
    QResponsesBLL.MoveResponseDown(
    questionResponseID, username );

    // reset the view to show the updates
    ResetView(); // rebinds the data to the GridView
    }// if
    }// QResponseGridView_RowCommand( sender, e )


    QuestionResponses Business class:

    public bool MoveResponseUp( int questionResponseID, string username )
    {
    try
    {
    Adapter.spMoveQuestionResponseUp(
    questionResponseID,
    GetUser( username ).UserId );

    return true;
    }
    catch( SqlException sqle )
    {
    return false;
    }// try/catch
    }// MoveResponseUp( questionResponseID, username )

    ****************

    -={ Kyle K. }=-
    Kyle K., Oct 4, 2006
    #1
    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. Shapper

    Is it possible to reorder a dataset?

    Shapper, Jun 19, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    611
    Brock Allen
    Jun 19, 2005
  2. farseer
    Replies:
    1
    Views:
    2,344
    farseer
    Jun 28, 2005
  3. =?Utf-8?B?RGFya28gS29ucmFk?=

    GridView reorder Columns

    =?Utf-8?B?RGFya28gS29ucmFk?=, Aug 7, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    810
    =?Utf-8?B?RGFya28gS29ucmFk?=
    Aug 7, 2006
  4. eagle

    reorder columns in a gridview

    eagle, Jul 28, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    1,561
    Eliyahu Goldin
    Jul 29, 2007
  5. eagle

    Re: reorder columns in a gridview

    eagle, Aug 2, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    429
    eagle
    Aug 2, 2007
Loading...

Share This Page