Professional Web Applications Themes

Add Confirm to Delete button in repeater - ASP.NET Data Grid Control

I have a repeater which shows Group names. (Skip this part if you want rather irrelevant) The groups are ordered and formatted: Parent ---Child ------Grand Child (okay start reading again please) The code (html side) looks like this: <table id="Table1"> <asp:Repeater id="rptGroups" runat="server" OnItemCommand="Button_ItemCommand"> <HeaderTemplate> </HeaderTemplate> <ItemTemplate> <tr> <td> <img width='<%# Int32.p(DataBinder.Eval(Container.DataItem, "lvl") * 20) %>' height="1" /> <asp:Label Runat="server" CssClass="FormFieldLabel"> <%# DataBinder.Eval(Container.DataItem, "GroupName") %> </asp:Label> </td> <td> <asp:LinkButton CommandName="ID" Text='<%#DataBinder.GetPropertyValue(me, "SelectUserButtonName")%>' CommandArgument='<%#DataBinder.Eval(Container.Data Item, "GrpID")%>' runat="server" ID="Linkbutton1" CssClass="FormLnkBtn" /> </td> </tr> </ItemTemplate> <FooterTemplate> </FooterTemplate> </asp:Repeater> </table> the link button line: <asp:LinkButton CommandName="ID" Text='<%#DataBinder.GetPropertyValue(me, "SelectUserButtonName")%>' CommandArgument='<%#DataBinder.Eval(Container.Data Item, "GrpID")%>' runat="server" ID="Linkbutton1" CssClass="FormLnkBtn" ...

  1. #1

    Default Add Confirm to Delete button in repeater

    I have a repeater which shows Group names.

    (Skip this part if you want rather irrelevant)
    The groups are ordered and formatted:
    Parent
    ---Child
    ------Grand Child

    (okay start reading again please)

    The code (html side) looks like this:



    <table id="Table1">

    <asp:Repeater id="rptGroups" runat="server"
    OnItemCommand="Button_ItemCommand">

    <HeaderTemplate>

    </HeaderTemplate>

    <ItemTemplate>

    <tr>

    <td>

    <img width='<%# Int32.p(DataBinder.Eval(Container.DataItem, "lvl")
    * 20) %>' height="1" />

    <asp:Label Runat="server" CssClass="FormFieldLabel">

    <%# DataBinder.Eval(Container.DataItem, "GroupName") %>

    </asp:Label>

    </td>

    <td>

    <asp:LinkButton CommandName="ID"
    Text='<%#DataBinder.GetPropertyValue(me, "SelectUserButtonName")%>'
    CommandArgument='<%#DataBinder.Eval(Container.Data Item, "GrpID")%>'
    runat="server" ID="Linkbutton1" CssClass="FormLnkBtn" />

    </td>

    </tr>

    </ItemTemplate>

    <FooterTemplate>

    </FooterTemplate>

    </asp:Repeater>

    </table>



    the link button line:


    <asp:LinkButton CommandName="ID" Text='<%#DataBinder.GetPropertyValue(me,
    "SelectUserButtonName")%>'
    CommandArgument='<%#DataBinder.Eval(Container.Data Item, "GrpID")%>'
    runat="server" ID="Linkbutton1" CssClass="FormLnkBtn" />



    Creates a link button, sets the text = the value of "SelectUserButtonName"
    property of the parent page (this phrase is dynamically changed depending on
    the language of the user).

    It adds a CommandArgument which happens to be the key field value for that
    group. Currently when a user clicks the button the code collects the value
    from the CommandArguement to know which row to work with.



    Sub Button_ItemCommand(ByVal Sender As Object, _

    ByVal e As RepeaterCommandEventArgs)

    If e.CommandName = "ID" Then

    'PopUp(e.CommandArgument.ToString() + " " + hdnFor.Value)

    RaiseEvent UserSelected(e.CommandArgument.ToString)

    End If

    End Sub


    I want to dynamically add code to confirm a delete.

    I have done this before with regular buttons and link buttons however, as
    this one seems to be dynamically added I can't refer to it by ID because I
    get an error saying it doesn't exist.

    Here is how the HTML renders right now:



    <a id="ShowGroupMembership1_rptGroups__ctl6_Linkbutto n1" class="FormLnkBtn"
    href="javascript:{if (typeof(Page_ClientValidate) != 'function' ||
    Page_ClientValidate())
    __doPostBack('ShowGroupMembership1$rptGroups$_ctl6 $Linkbutton1','')}
    ">Delete</a>



    as you can see the id is NOT LinkButton1 anymore, so of course I cannot find
    it.

    Just to make things a bit more difficult, this is a control and depending on
    parameters set it can either delete the group OR simply Raise and event to
    the parent sending the key field value of the selected group.

    I am currently trying to get the confirm delete to work.

    Thanks for your time!

    Oh, VB please..
    I did find this link:
    [url]http://davidhayden.com/blog/dave/archive/2004/03/16/178.aspx[/url]
    but I haven't figured out how to convert from C#


    Roger Twomey Guest

  2. #2

    Default Re: Add Confirm to Delete button in repeater

    Roger,
    I haven't worked with the repeater command enough to offer a repeater
    specific solution, but here is a snippet I use for the datagrid
    ItemDataBound command...
    The trick to this is knowing which table cell index contains, in this case,
    the image button used for the delete action on the button. Works like a
    charm for the datagrid.

    --Morgan

    Private Sub grdInvoiceLines_ItemDataBound(ByVal sender As Object, ByVal
    e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    grdInvoiceLines.ItemDataBound
    Select Case e.Item.ItemType
    Case ListItemType.Item, ListItemType.AlternatingItem
    Dim myTableCell As TableCell
    Dim myEditCell As TableCell
    myTableCell = e.Item.Cells(6)
    myEditCell = e.Item.Cells(5)
    Dim myDeleteButton As ImageButton
    myDeleteButton = CType(myTableCell.Controls(1),
    System.Web.UI.WebControls.ImageButton)
    myDeleteButton.Attributes.Add("onclick", "return
    confirm('Are you Sure you want to delete this Line Item?');")
    End Select
    End Sub

    "Roger Twomey" <rogerdevvnet.on.ca> wrote in message
    news:ezB28DlSEHA.1168TK2MSFTNGP11.phx.gbl...
    > I have a repeater which shows Group names.
    >
    > (Skip this part if you want rather irrelevant)
    > The groups are ordered and formatted:
    > Parent
    > ---Child
    > ------Grand Child
    >
    > (okay start reading again please)
    >
    > The code (html side) looks like this:
    >
    >
    >
    > <table id="Table1">
    >
    > <asp:Repeater id="rptGroups" runat="server"
    > OnItemCommand="Button_ItemCommand">
    >
    > <HeaderTemplate>
    >
    > </HeaderTemplate>
    >
    > <ItemTemplate>
    >
    > <tr>
    >
    > <td>
    >
    > <img width='<%# Int32.p(DataBinder.Eval(Container.DataItem, "lvl")
    > * 20) %>' height="1" />
    >
    > <asp:Label Runat="server" CssClass="FormFieldLabel">
    >
    > <%# DataBinder.Eval(Container.DataItem, "GroupName") %>
    >
    > </asp:Label>
    >
    > </td>
    >
    > <td>
    >
    > <asp:LinkButton CommandName="ID"
    > Text='<%#DataBinder.GetPropertyValue(me, "SelectUserButtonName")%>'
    > CommandArgument='<%#DataBinder.Eval(Container.Data Item, "GrpID")%>'
    > runat="server" ID="Linkbutton1" CssClass="FormLnkBtn" />
    >
    > </td>
    >
    > </tr>
    >
    > </ItemTemplate>
    >
    > <FooterTemplate>
    >
    > </FooterTemplate>
    >
    > </asp:Repeater>
    >
    > </table>
    >
    >
    >
    > the link button line:
    >
    >
    > <asp:LinkButton CommandName="ID" Text='<%#DataBinder.GetPropertyValue(me,
    > "SelectUserButtonName")%>'
    > CommandArgument='<%#DataBinder.Eval(Container.Data Item, "GrpID")%>'
    > runat="server" ID="Linkbutton1" CssClass="FormLnkBtn" />
    >
    >
    >
    > Creates a link button, sets the text = the value of "SelectUserButtonName"
    > property of the parent page (this phrase is dynamically changed depending
    on
    > the language of the user).
    >
    > It adds a CommandArgument which happens to be the key field value for that
    > group. Currently when a user clicks the button the code collects the value
    > from the CommandArguement to know which row to work with.
    >
    >
    >
    > Sub Button_ItemCommand(ByVal Sender As Object, _
    >
    > ByVal e As RepeaterCommandEventArgs)
    >
    > If e.CommandName = "ID" Then
    >
    > 'PopUp(e.CommandArgument.ToString() + " " + hdnFor.Value)
    >
    > RaiseEvent UserSelected(e.CommandArgument.ToString)
    >
    > End If
    >
    > End Sub
    >
    >
    > I want to dynamically add code to confirm a delete.
    >
    > I have done this before with regular buttons and link buttons however, as
    > this one seems to be dynamically added I can't refer to it by ID because I
    > get an error saying it doesn't exist.
    >
    > Here is how the HTML renders right now:
    >
    >
    >
    > <a id="ShowGroupMembership1_rptGroups__ctl6_Linkbutto n1"
    class="FormLnkBtn"
    > href="javascript:{if (typeof(Page_ClientValidate) != 'function' ||
    > Page_ClientValidate())
    > __doPostBack('ShowGroupMembership1$rptGroups$_ctl6 $Linkbutton1','')}
    > ">Delete</a>
    >
    >
    >
    > as you can see the id is NOT LinkButton1 anymore, so of course I cannot
    find
    > it.
    >
    > Just to make things a bit more difficult, this is a control and depending
    on
    > parameters set it can either delete the group OR simply Raise and event to
    > the parent sending the key field value of the selected group.
    >
    > I am currently trying to get the confirm delete to work.
    >
    > Thanks for your time!
    >
    > Oh, VB please..
    > I did find this link:
    > [url]http://davidhayden.com/blog/dave/archive/2004/03/16/178.aspx[/url]
    > but I haven't figured out how to convert from C#
    >
    >

    Morgan Guest

Similar Threads

  1. Confirm before delete
    By Pixel Pusher in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 1
    Last Post: November 10th, 05:47 AM
  2. Confirm Delete in DataGrid
    By in forum ASP.NET Data Grid Control
    Replies: 19
    Last Post: September 14th, 09:06 AM
  3. flash form and confirm delete
    By Ian O'Betz in forum Macromedia ColdFusion
    Replies: 7
    Last Post: March 1st, 05:05 PM
  4. confirm before delete ?
    By mark in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: May 20th, 02:15 PM
  5. confirm delete prompt
    By Oliver Jobson in forum Windows XP/2000/ME
    Replies: 1
    Last Post: July 6th, 09:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139