GridView reorder problems

K

Kyle K.

(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. }=-
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top