I have a grid that I am trying to move the grid rows either up or down based on button click. Here is what I have so far.

 Protected Sub imgBtnMoveUp_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        Dim imgBtn As ImageButton
        Dim FirstRow As GridViewRow = gvQuoteSo.Rows(0)
        Dim btnUp As Button = DirectCast(FirstRow.FindControl("MoveUp"), Button)
        Dim gvrow As GridViewRow
        Dim previousRow As GridViewRow
        Dim index As Integer = 0

        imgBtn = CType(sender, ImageButton)

        If imgBtn.CommandName = "MoveUp" Then
            index = Convert.ToInt32(imgBtn.CommandArgument)
            gvrow = gvQuoteSo.Rows(index)
            previousRow = gvQuoteSo.Rows(index - 1)

            UpdatePanelGrid.Update()


        End If

    End Sub

When I click the button for up nothing hapens. I know this is just the move up function but if I can get help with that then the move down will answer itself. Thanks so much!

I don't know if you can't directly in the grid, I think you need to update your list/array and bind it again.
Something like this:

 Protected Sub imgBtnMoveUp_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)

        Dim myList As List<MyClass>  ' This should be the array used to bind the grid
        Dim imgBtn As ImageButton
        Dim oldIndex As Integer = 0
        Dim newIndex As Integer = 0

        imgBtn = CType(sender, ImageButton)
        oldIndex = Convert.ToInt32(imgBtn.CommandArgument)

        Dim item as MyClass = myList(oldIndex)

        If imgBtn.CommandName = "MoveUp" Then
            newIndex = oldIndex - 1 'Must handle if this isn't already the first item
        Else
            newIndex = oldIndex + 1 'Must handle if this isn't already the last item
        End If


        myList.RemoveItem(oldIndex)
        myList.InsertItem(newIndex, item)
        'Some collections have the Move method: 
        'myList.Move(oldIndex, newIndex)

        myGrid.DataSource = myList
        myGrid.DataBind()

    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.