I posted this in another place and was directed to this forum.
I have a datatable being stored as a Session and it databinds to a gridview. In this gridview I created a "Select" button and made its function to Duplicate the selected row.
ex. Duplicate row 1... then it adds that row to the datatable again.
the BindData() is
This DOES duplicate the row to itself. However the issue now is this..
ex.
Before Duplication click
Row 1
After Duplication Click
Row 1
Row 1
Row 1
YES three rows instead of just two. I have tried everything I can think of for the past couple of hours and can't get it to just add 1 row.
Here is the page side code
If you put an updatepanel within a panel it allows you to maintain the scrolling position within a gridview when it performs a "postback
I have a datatable being stored as a Session and it databinds to a gridview. In this gridview I created a "Select" button and made its function to Duplicate the selected row.
ex. Duplicate row 1... then it adds that row to the datatable again.
Code:
Protected Sub gvQueue_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvQueue.RowCommand
If e.CommandName = "Select" Then
'Retrieve the table from the session object.
Dim dt = CType(Session("myDatatable"), DataTable)
'Dims Index
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
'Selects row to copy
Dim row = dt.Rows(index)
'Adds row to bottom of data table
For Each dr As DataRow In dt.Rows
dt.ImportRow(row)
Next
BindData()
lblQueue.Text = gvQueue.Rows.Count
End If
End Sub
the BindData() is
Code:
Private Sub BindData()
gvQueue.DataSource = (CType(Session("myDatatable"), DataTable))
gvQueue.DataBind()
End Sub
This DOES duplicate the row to itself. However the issue now is this..
ex.
Before Duplication click
Row 1
After Duplication Click
Row 1
Row 1
Row 1
YES three rows instead of just two. I have tried everything I can think of for the past couple of hours and can't get it to just add 1 row.
Here is the page side code
Code:
<asp:Panel ID="pnlTable" runat="server" Width="100%" ScrollBars="Both" Height="175px">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:GridView ID="gvQueue" runat="server" Font-Size="Small"
HorizontalAlign="Center" CellPadding="4" ForeColor="#333333" GridLines="None"
OnRowEditing="gvQueue_RowEditing"
OnRowCancelingEdit="gvQueue_RowCancelingEdit"
OnRowUpdating="gvQueue_RowUpdating"
OnPageIndexChanging="gvQueue_PageIndexChanging"
AutoGenerateColumns="False" AllowSorting="True"
OnSorting="gvQueue_Sorting"
OnRowCommand="gvQueue_RowCommand">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowEditButton="True" ButtonType="Button" />
<asp:CommandField SelectText="Duplicate" ShowSelectButton="True" ButtonType="Button" />
<asp:CommandField ShowDeleteButton="True" ButtonType="Button" />
***I REMOVED THE REST OF THE COLUMNS FOR CONVENIENCE*** </Columns>
<EditRowStyle BackColor="#999999" HorizontalAlign="Center" Wrap="False" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"/>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" Wrap="False" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Center" Wrap="False" />
<SortedAscendingCellStyle BackColor="#E9E7E2" Wrap="False" />
<SortedAscendingHeaderStyle BackColor="#506C8C" Wrap="False" />
<SortedDescendingCellStyle BackColor="#FFFDF8" Wrap="False" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" Wrap="False" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
If you put an updatepanel within a panel it allows you to maintain the scrolling position within a gridview when it performs a "postback