473,390 Members | 1,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

DataList.DeleteCommand event is not getting fired

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
4 2781
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Barry | last post by:
Hi, I have a Datalist inside the ItemTemplate of another DataList. When I drilldown, I'm not getting any data in either the itemtemplate or headertemplate of the second DataList. I've confirmed...
2
by: Chris Fink | last post by:
Hello, I have a datalist that contains an asp button. I have the need to pass a value that is bound to my datalist along the button when the on_click event is fired. My datalist creates a button...
0
by: Ashish Sharma | last post by:
I have a drop down list inside a data list on a form like this : <asp:DataList ID="DataList1" runat="server" EnableViewState="False"> <ItemTemplate> <asp:Label ID="lblname" Runat="server"...
5
by: TCORDON | last post by:
I have a DataList with a bunch of items (eg. Shoppiong Cart) each Item has a Remove button, in the code Behind page I have a Sub called Remove Item which calls a Function like this: Public...
4
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
2
by: cindy | last post by:
When my datalist loads I am trying to make the checked value in a radio button group reflect which value is stored in the data and then fire and event when the CheckChanged event fires. private...
2
by: haroldsphsu | last post by:
Hi all, I created a DataList on a WebForm, and I want to have a separate delete button at the bottom of the page. I can create a event handler for the delete button and delete the selected item...
1
by: Gary | last post by:
I'm having a problem with the DataList control, my situation is as follows... I have a DataList with a Drop Down List Box (DDLB) in the header, this DDLB is set to AutoPostBack = True. When the...
0
by: Nathan Sokalski | last post by:
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.