0

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!

2
Contributors
1
Reply
17
Views
3 Years
Discussion Span
Last Post by AleMonteiro
0

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.