Hello!
In VB.NET I have a GridView that shows a list of dates and beside each date there's a delete button.
For a reason I don't know, the delete event seems to be fired twice, but I have trouble finding the exact source of the problem.
From this thread : http://bytes.com/forum/threadnav436365-1-10.html, I have set my command button as a template field and call "GridView1.Dele teRow(Int32.Par se(e.CommandArg ument.ToString( )))" when the button is clicked.
Just above that line, I call a method that logs whatever I want : Logger("[DEBUG] ImageButton1_Co mmand"). In the log file, I see only one entry, as if the block of code is executed only once.
But when I use SqlProfiler to see what's happening at the server's level, I see that my stored procedure is called twice because I have two following line two times :
exec pln_add_excepti on @date='2008-09-07 00:00:00:000',@ planification_i d=9
......
My VB code :
My GridView :
In VB.NET I have a GridView that shows a list of dates and beside each date there's a delete button.
For a reason I don't know, the delete event seems to be fired twice, but I have trouble finding the exact source of the problem.
From this thread : http://bytes.com/forum/threadnav436365-1-10.html, I have set my command button as a template field and call "GridView1.Dele teRow(Int32.Par se(e.CommandArg ument.ToString( )))" when the button is clicked.
Just above that line, I call a method that logs whatever I want : Logger("[DEBUG] ImageButton1_Co mmand"). In the log file, I see only one entry, as if the block of code is executed only once.
But when I use SqlProfiler to see what's happening at the server's level, I see that my stored procedure is called twice because I have two following line two times :
exec pln_add_excepti on @date='2008-09-07 00:00:00:000',@ planification_i d=9
......
My VB code :
Code:
Protected Sub ImageButton1_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
Logger("[DEBUG] ImageButton1_Command")
GridView1.DeleteRow(Int32.Parse(e.CommandArgument.ToString()))
End Sub
Private Sub Logger(ByVal message As String)
Dim logEntry As New LogEntry()
logEntry.EventId = 100
logEntry.Priority = 1
logEntry.Title = "Logging message"
logEntry.Message = message
logEntry.Categories.Add("General")
Logger.Write(logEntry)
End Sub
Code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlServerExecutionsPlanifiees" DataKeyNames="date" EnableViewState="False">
<Columns>
<asp:TemplateField HeaderText="date" SortExpression="date">
<ItemTemplate>
<asp:Label ID="dateLabel" runat="server" Text='<%# Eval("date", "{0:d}") %>' CssClass='<%# "planifDate" & CType(Eval("planifie"), String) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton runat="server" id="ImageButton1" CommandName="Delete" ImageUrl="images/delete.png" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>' OnCommand="ImageButton1_Command" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Comment