DataList.DeleteCommand event is not getting fired

Discussion in 'ASP .Net Datagrid Control' started by Nathan Sokalski, May 21, 2006.

  1. 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","newsinfo/{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

    http://www.nathansokalski.com/
    Nathan Sokalski, May 21, 2006
    #1
    1. Advertising

  2. 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","newsinfo/{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
    >
    > http://www.nathansokalski.com/
    >
    >
    >
    Altaf Al-Amin Najwani, May 21, 2006
    #2
    1. Advertising

  3. 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

    http://www.nathansokalski.com/

    "Altaf Al-Amin Najwani" <> wrote in message
    news:...
    > 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","newsinfo/{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
    >>
    >> http://www.nathansokalski.com/
    >>
    >>
    >>
    Nathan Sokalski, May 21, 2006
    #3
  4. 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
    >
    > http://www.nathansokalski.com/
    >
    > "Altaf Al-Amin Najwani" <> wrote in message
    > news:...
    > > 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","newsinfo/{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
    > >>
    > >> http://www.nathansokalski.com/
    > >>
    > >>
    > >>

    >
    >
    >
    Altaf Al-Amin Najwani, May 21, 2006
    #4
  5. 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

    http://www.nathansokalski.com/

    "Altaf Al-Amin Najwani" <> wrote in message
    news:...
    > 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
    >>
    >> http://www.nathansokalski.com/
    >>
    >> "Altaf Al-Amin Najwani" <> wrote in message
    >> news:...
    >> > 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","newsinfo/{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
    >> >>
    >> >> http://www.nathansokalski.com/
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
    Nathan Sokalski, May 21, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. XueWu
    Replies:
    0
    Views:
    613
    XueWu
    Jul 12, 2005
  2. Nathan Sokalski
    Replies:
    4
    Views:
    3,515
    Nathan Sokalski
    May 21, 2006
  3. jobs
    Replies:
    0
    Views:
    1,473
  4. nirbhay

    DataList and Event not fired

    nirbhay, Apr 14, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    181
    Teemu Keiski
    Apr 22, 2006
  5. Nathan Sokalski

    DataList.DeleteCommand event is not getting fired

    Nathan Sokalski, May 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    145
    Nathan Sokalski
    May 21, 2006
Loading...

Share This Page