To Move row up/down:
1.Place the below template column inside your column tag in Datagrid
<asp:TemplateColumn> <ItemTemplate> <asp:ImageButton runat="server" ToolTip="Click to move this row up" ImageUrl="~/Images/Up.gif" ID="btnUp" CommandName="MoveUp" /> </ItemTemplate> </asp:TemplateColumn>
2.Place Up.gif(or what ever the image you wants) inside the image folder of the root of your website.
3. Paste the below code inside the item command of your grid
Private Sub YourDataGrid_ItemCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs) Dim rowID As Int32 = DirectCast(dgMainMenu.DataKeys(e.Item.ItemIndex), Int32)
Dim rowIndex As Int32 = 0 Dim rowToBeMoved As DataRow = Maindt.NewRow() For i As Int16 = 0 To CShort(Maindt.Rows.Count - 1) 'create a copy of the row to be moved If Maindt.Rows(i)("MNU_MENU_ID").Equals(rowID) Then rowIndex = i rowToBeMoved("MNU_MENU_ID") = Maindt.Rows(i)("MNU_MENU_ID") rowToBeMoved("MNU_ITEM_NAME") = Maindt.Rows(i)("MNU_ITEM_NAME") rowToBeMoved("MNU_ITEM_URL") = Maindt.Rows(i)("MNU_ITEM_URL") Exit For End If Next
Select Case e.CommandName Case "MoveUp" If rowIndex > 0 Then 'delete the selected row Maindt.Rows(rowIndex).Delete() Maindt.AcceptChanges() 'add the rowToBeMoved Maindt.Rows.InsertAt(rowToBeMoved, rowIndex - 1) Maindt.AcceptChanges()
dgMainMenu.SelectedIndex = rowIndex - 1 End If Exit Select Case "MoveDown" If rowIndex < Maindt.Rows.Count - 1 Then Maindt.Rows(rowIndex).Delete() Maindt.AcceptChanges() Maindt.Rows.InsertAt(rowToBeMoved, rowIndex + 1) Maindt.AcceptChanges() dgMainMenu.SelectedIndex = rowIndex + 1 End If Exit Select Case "Jump" Try Dim txtJumpTemp As TextBox = CType(e.Item.FindControl("txtJump"), TextBox) Dim jumprowIndex As Integer = CInt(txtJumpTemp.Text) If rowIndex >= 0 And rowIndex < Maindt.Rows.Count Then 'delete the selected row Maindt.Rows(rowIndex).Delete() Maindt.AcceptChanges() 'add the rowToBeMoved Maindt.Rows.InsertAt(rowToBeMoved, jumprowIndex - 1) Maindt.AcceptChanges()
dgMainMenu.SelectedIndex = jumprowIndex - 1 End If Catch ex As Exception 'ShowMessage("Specify a Row No. - Should be an Integer") End Try
Exit Select End Select
Session("MainOrder") = Maindt End Sub
.. To be continued... The article is not a completed one!.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|