Question Gridview row_deleting fires twice.

nsoni

Member
Joined
Jan 6, 2008
Messages
11
Programming Experience
1-3
Hello Everybody,
I was trying to delete a row from GridView the method called in row_deleting gets fired twice so two row got deleted.

I am pasting below my code aspx + vb.

<asp:GridView ID="GridView1" AutoGenerateColumns="False" DataKeyNames="APROFILE_ID" OnRowDeleting="GridView1_RowDeleting" Height="40px" Width="659px" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" Caption="ACADEMIC PROFILE DETAILS" CaptionAlign="Left" CellPadding="4" runat="server">
<RowStyle BackColor="White" ForeColor="#003399" />
<Columns>
<asp:BoundField DataField="DEGREE" HeaderText="DEGREE/COURSE" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="ESTABLISHMENT" HeaderText="UNIVERSITY" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="STARTDATE" HeaderText="FROM" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="ENDDATE" HeaderText="TO" ReadOnly="True"></asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkdel" runat="server" Text="Delete" CommandName="Delete"></asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
</Columns>

<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="DimGray" Font-Bold="True" ForeColor="#CCCCFF" />
</asp:GridView>





Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Dim aprofileid As Integer = Integer.Parse(GridView1.DataKeys(e.RowIndex).Value.ToString())

Dim oCn As OracleConnection = New OracleConnection(dbcls.GetORACLEConnectionString)
Dim oCmd As OracleCommand
Dim oDA As OracleDataAdapter
Dim oDs As New DataSet
Try
Dim sqlstring As String = ""
oCmd = New OracleCommand(sqlstring, oCn)
oDA = New OracleDataAdapter(oCmd)
oCn.Open()
oDA.DeleteCommand = New OracleCommand("Delete from ACADEMICPROFILE where APROFILE_ID=" & aprofileid, oCn)
oDA.DeleteCommand.ExecuteNonQuery()
oCn.Close()
ViewAcademicProfile()
Catch ex As Exception
Me.Message1.InnerHtml = ex.Message
Finally
If oCn.State = ConnectionState.Open Then
oCn.Close()
End If
End Try

End Sub

Can Anybody advice please

Reagrds
Thankx
 

Latest posts

Back
Top