By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 801 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

DataList.DeleteCommand event is not getting fired

P: n/a
I have a DataList that has an Button as one of the controls in it's
ItemTemplate. The Button has a CommandName="delete" attribute, but when I
click it the DeleteCommand event doesn't even get fired. I have checked
everything I could think of, but everything looks correct to me. Here is the
relevant code from the *.aspx file and the *.aspx.vb files (if I missed
something that is relevant, let me know):
ASPX File:

<asp:datalist id="datImages" runat="server" EnableViewState="False"
CellPadding="0" CellSpacing="5" RepeatColumns="3"
RepeatDirection="Horizontal" DataKeyField="contentid">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Bottom"></ItemStyle>
<ItemTemplate>
<uc1:captionimage id="CapImg" runat="server" EnableViewState="False"
photo='<%#
DataBinder.Eval(Container,"DataItem.content","news info/{0}").Trim() %>'
caption='<%# DataBinder.Eval(Container, "DataItem.textcaption").Trim()
%>'></uc1:captionimage><BR><BR>
<asp:Button id="btnDeleteImg" runat="server" CausesValidation="False"
Font-Bold="True" EnableViewState="False" Text="Delete"
CommandName="delete"></asp:Button>
</ItemTemplate>
</asp:datalist>

ASPX.VB File:

Private Sub datImages_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
datImages.DeleteCommand
Dim cmdDelete As New OleDbCommand("DELETE FROM newsinfo WHERE contentid=" &
CInt(datLinksFiles.DataKeys(e.Item.ItemIndex)), New
OleDbConnection(Global.connectionstring))

cmdDelete.Connection.Open()
cmdDelete.ExecuteNonQuery()
cmdDelete.Connection.Close()
If System.IO.File.Exists(Server.MapPath("newsinfo/" &
CStr(CType(e.Item.DataItem, DataRowView).Row("content")))) Then
System.IO.File.Delete(Server.MapPath("newsinfo/" &
CStr(CType(e.Item.DataItem, DataRowView).Row("content"))))
Me.RefreshResults()
End Sub
Does anybody have any idea what could be causing the datImages.DeleteCommand
event not to be raised? Thank you.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
May 21 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
it seems you havent bind DataList Ondelete Command ... OnDeleteCommand =
"datImages_DeleteCommand" in data list properties in html

"Nathan Sokalski" wrote:
I have a DataList that has an Button as one of the controls in it's
ItemTemplate. The Button has a CommandName="delete" attribute, but when I
click it the DeleteCommand event doesn't even get fired. I have checked
everything I could think of, but everything looks correct to me. Here is the
relevant code from the *.aspx file and the *.aspx.vb files (if I missed
something that is relevant, let me know):
ASPX File:

<asp:datalist id="datImages" runat="server" EnableViewState="False"
CellPadding="0" CellSpacing="5" RepeatColumns="3"
RepeatDirection="Horizontal" DataKeyField="contentid">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Bottom"></ItemStyle>
<ItemTemplate>
<uc1:captionimage id="CapImg" runat="server" EnableViewState="False"
photo='<%#
DataBinder.Eval(Container,"DataItem.content","news info/{0}").Trim() %>'
caption='<%# DataBinder.Eval(Container, "DataItem.textcaption").Trim()
%>'></uc1:captionimage><BR><BR>
<asp:Button id="btnDeleteImg" runat="server" CausesValidation="False"
Font-Bold="True" EnableViewState="False" Text="Delete"
CommandName="delete"></asp:Button>
</ItemTemplate>
</asp:datalist>

ASPX.VB File:

Private Sub datImages_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
datImages.DeleteCommand
Dim cmdDelete As New OleDbCommand("DELETE FROM newsinfo WHERE contentid=" &
CInt(datLinksFiles.DataKeys(e.Item.ItemIndex)), New
OleDbConnection(Global.connectionstring))

cmdDelete.Connection.Open()
cmdDelete.ExecuteNonQuery()
cmdDelete.Connection.Close()
If System.IO.File.Exists(Server.MapPath("newsinfo/" &
CStr(CType(e.Item.DataItem, DataRowView).Row("content")))) Then
System.IO.File.Delete(Server.MapPath("newsinfo/" &
CStr(CType(e.Item.DataItem, DataRowView).Row("content"))))
Me.RefreshResults()
End Sub
Does anybody have any idea what could be causing the datImages.DeleteCommand
event not to be raised? Thank you.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

May 21 '06 #2

P: n/a
That is not how event bubbling is done. I have several other applications
that I use the DeleteCommand event in, and I don't need to do any manual
binding in those, I even have another DataList on this same page, and that
one works. The connection between the event and the event handler is done
using the "Handles" clause in VB.NET, which I have if you look at the code I
included in my original posting. Any other suggestions?
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Altaf Al-Amin Najwani" <al**********@gmail.com> wrote in message
news:85**********************************@microsof t.com...
it seems you havent bind DataList Ondelete Command ... OnDeleteCommand =
"datImages_DeleteCommand" in data list properties in html

"Nathan Sokalski" wrote:
I have a DataList that has an Button as one of the controls in it's
ItemTemplate. The Button has a CommandName="delete" attribute, but when I
click it the DeleteCommand event doesn't even get fired. I have checked
everything I could think of, but everything looks correct to me. Here is
the
relevant code from the *.aspx file and the *.aspx.vb files (if I missed
something that is relevant, let me know):
ASPX File:

<asp:datalist id="datImages" runat="server" EnableViewState="False"
CellPadding="0" CellSpacing="5" RepeatColumns="3"
RepeatDirection="Horizontal" DataKeyField="contentid">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Bottom"></ItemStyle>
<ItemTemplate>
<uc1:captionimage id="CapImg" runat="server" EnableViewState="False"
photo='<%#
DataBinder.Eval(Container,"DataItem.content","news info/{0}").Trim() %>'
caption='<%# DataBinder.Eval(Container, "DataItem.textcaption").Trim()
%>'></uc1:captionimage><BR><BR>
<asp:Button id="btnDeleteImg" runat="server" CausesValidation="False"
Font-Bold="True" EnableViewState="False" Text="Delete"
CommandName="delete"></asp:Button>
</ItemTemplate>
</asp:datalist>

ASPX.VB File:

Private Sub datImages_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
datImages.DeleteCommand
Dim cmdDelete As New OleDbCommand("DELETE FROM newsinfo WHERE
contentid=" &
CInt(datLinksFiles.DataKeys(e.Item.ItemIndex)), New
OleDbConnection(Global.connectionstring))

cmdDelete.Connection.Open()
cmdDelete.ExecuteNonQuery()
cmdDelete.Connection.Close()
If System.IO.File.Exists(Server.MapPath("newsinfo/" &
CStr(CType(e.Item.DataItem, DataRowView).Row("content")))) Then
System.IO.File.Delete(Server.MapPath("newsinfo/" &
CStr(CType(e.Item.DataItem, DataRowView).Row("content"))))
Me.RefreshResults()
End Sub
Does anybody have any idea what could be causing the
datImages.DeleteCommand
event not to be raised? Thank you.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

May 21 '06 #3

P: n/a
Does your another datalist has itemtemplate and button in item template????
Have you tried my solution??? There is no harm in writing one line in html i
think .... I have checked on my side and its work when ondeletecommand is
specified otherwise not. And you said about event bubbling ... Before event
bubbling postback javascript is generated which calls particular event
handler :) if you dont tell to your datalist who is handling delete command
what will be written in generated postback javascript?????

"Nathan Sokalski" wrote:
That is not how event bubbling is done. I have several other applications
that I use the DeleteCommand event in, and I don't need to do any manual
binding in those, I even have another DataList on this same page, and that
one works. The connection between the event and the event handler is done
using the "Handles" clause in VB.NET, which I have if you look at the code I
included in my original posting. Any other suggestions?
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Altaf Al-Amin Najwani" <al**********@gmail.com> wrote in message
news:85**********************************@microsof t.com...
it seems you havent bind DataList Ondelete Command ... OnDeleteCommand =
"datImages_DeleteCommand" in data list properties in html

"Nathan Sokalski" wrote:
I have a DataList that has an Button as one of the controls in it's
ItemTemplate. The Button has a CommandName="delete" attribute, but when I
click it the DeleteCommand event doesn't even get fired. I have checked
everything I could think of, but everything looks correct to me. Here is
the
relevant code from the *.aspx file and the *.aspx.vb files (if I missed
something that is relevant, let me know):
ASPX File:

<asp:datalist id="datImages" runat="server" EnableViewState="False"
CellPadding="0" CellSpacing="5" RepeatColumns="3"
RepeatDirection="Horizontal" DataKeyField="contentid">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Bottom"></ItemStyle>
<ItemTemplate>
<uc1:captionimage id="CapImg" runat="server" EnableViewState="False"
photo='<%#
DataBinder.Eval(Container,"DataItem.content","news info/{0}").Trim() %>'
caption='<%# DataBinder.Eval(Container, "DataItem.textcaption").Trim()
%>'></uc1:captionimage><BR><BR>
<asp:Button id="btnDeleteImg" runat="server" CausesValidation="False"
Font-Bold="True" EnableViewState="False" Text="Delete"
CommandName="delete"></asp:Button>
</ItemTemplate>
</asp:datalist>

ASPX.VB File:

Private Sub datImages_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
datImages.DeleteCommand
Dim cmdDelete As New OleDbCommand("DELETE FROM newsinfo WHERE
contentid=" &
CInt(datLinksFiles.DataKeys(e.Item.ItemIndex)), New
OleDbConnection(Global.connectionstring))

cmdDelete.Connection.Open()
cmdDelete.ExecuteNonQuery()
cmdDelete.Connection.Close()
If System.IO.File.Exists(Server.MapPath("newsinfo/" &
CStr(CType(e.Item.DataItem, DataRowView).Row("content")))) Then
System.IO.File.Delete(Server.MapPath("newsinfo/" &
CStr(CType(e.Item.DataItem, DataRowView).Row("content"))))
Me.RefreshResults()
End Sub
Does anybody have any idea what could be causing the
datImages.DeleteCommand
event not to be raised? Thank you.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/


May 21 '06 #4

P: n/a
My other DataList has a Button in the ItemTemplate, they are almost the same
except for the data that they are binded to. But because you are not
supposed to need to add the code you mentioned, it means that something
somewhere got accidentally changed, and I want to know what & where that is
(if I always ignore stuff and do it the way it was not intended to be done,
what will happen when MS decides to make changes? How inefficient and sloppy
will my code be eventually? I think that when something doesn't work as
expected, I need to learn why so I can use it in the future in other
scenarios).
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Altaf Al-Amin Najwani" <al**********@gmail.com> wrote in message
news:2B**********************************@microsof t.com...
Does your another datalist has itemtemplate and button in item
template????
Have you tried my solution??? There is no harm in writing one line in html
i
think .... I have checked on my side and its work when ondeletecommand is
specified otherwise not. And you said about event bubbling ... Before
event
bubbling postback javascript is generated which calls particular event
handler :) if you dont tell to your datalist who is handling delete
command
what will be written in generated postback javascript?????

"Nathan Sokalski" wrote:
That is not how event bubbling is done. I have several other applications
that I use the DeleteCommand event in, and I don't need to do any manual
binding in those, I even have another DataList on this same page, and
that
one works. The connection between the event and the event handler is done
using the "Handles" clause in VB.NET, which I have if you look at the
code I
included in my original posting. Any other suggestions?
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Altaf Al-Amin Najwani" <al**********@gmail.com> wrote in message
news:85**********************************@microsof t.com...
> it seems you havent bind DataList Ondelete Command ... OnDeleteCommand
> =
> "datImages_DeleteCommand" in data list properties in html
>
> "Nathan Sokalski" wrote:
>
>> I have a DataList that has an Button as one of the controls in it's
>> ItemTemplate. The Button has a CommandName="delete" attribute, but
>> when I
>> click it the DeleteCommand event doesn't even get fired. I have
>> checked
>> everything I could think of, but everything looks correct to me. Here
>> is
>> the
>> relevant code from the *.aspx file and the *.aspx.vb files (if I
>> missed
>> something that is relevant, let me know):
>>
>>
>> ASPX File:
>>
>> <asp:datalist id="datImages" runat="server" EnableViewState="False"
>> CellPadding="0" CellSpacing="5" RepeatColumns="3"
>> RepeatDirection="Horizontal" DataKeyField="contentid">
>> <ItemStyle HorizontalAlign="Center"
>> VerticalAlign="Bottom"></ItemStyle>
>> <ItemTemplate>
>> <uc1:captionimage id="CapImg" runat="server" EnableViewState="False"
>> photo='<%#
>> DataBinder.Eval(Container,"DataItem.content","news info/{0}").Trim()
>> %>'
>> caption='<%# DataBinder.Eval(Container, "DataItem.textcaption").Trim()
>> %>'></uc1:captionimage><BR><BR>
>> <asp:Button id="btnDeleteImg" runat="server"
>> CausesValidation="False"
>> Font-Bold="True" EnableViewState="False" Text="Delete"
>> CommandName="delete"></asp:Button>
>> </ItemTemplate>
>> </asp:datalist>
>>
>>
>>
>> ASPX.VB File:
>>
>> Private Sub datImages_DeleteCommand(ByVal source As Object, ByVal e As
>> System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
>> datImages.DeleteCommand
>> Dim cmdDelete As New OleDbCommand("DELETE FROM newsinfo WHERE
>> contentid=" &
>> CInt(datLinksFiles.DataKeys(e.Item.ItemIndex)), New
>> OleDbConnection(Global.connectionstring))
>>
>> cmdDelete.Connection.Open()
>> cmdDelete.ExecuteNonQuery()
>> cmdDelete.Connection.Close()
>> If System.IO.File.Exists(Server.MapPath("newsinfo/" &
>> CStr(CType(e.Item.DataItem, DataRowView).Row("content")))) Then
>> System.IO.File.Delete(Server.MapPath("newsinfo/" &
>> CStr(CType(e.Item.DataItem, DataRowView).Row("content"))))
>> Me.RefreshResults()
>> End Sub
>>
>>
>> Does anybody have any idea what could be causing the
>> datImages.DeleteCommand
>> event not to be raised? Thank you.
>> --
>> Nathan Sokalski
>> nj********@hotmail.com
>> http://www.nathansokalski.com/
>>
>>
>>


May 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.