Add Confirm to Delete button in repeater

Discussion in 'ASP .Net Datagrid Control' started by Roger Twomey, Jun 4, 2004.

  1. Roger Twomey

    Roger Twomey Guest

    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.parse(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.DataItem, "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.DataItem, "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_Linkbutton1" 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:
    http://davidhayden.com/blog/dave/archive/2004/03/16/178.aspx
    but I haven't figured out how to convert from C#
     
    Roger Twomey, Jun 4, 2004
    #1
    1. Advertising

  2. Roger Twomey

    Morgan Guest

    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" <> wrote in message
    news:...
    > 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.parse(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.DataItem, "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.DataItem, "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_Linkbutton1"

    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:
    > http://davidhayden.com/blog/dave/archive/2004/03/16/178.aspx
    > but I haven't figured out how to convert from C#
    >
    >
     
    Morgan, Jun 5, 2004
    #2
    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. Sandy
    Replies:
    1
    Views:
    7,243
    =?Utf-8?B?TWF1cmljaW9ERw==?=
    Jun 11, 2004
  2. Mike P
    Replies:
    1
    Views:
    4,143
  3. Replies:
    0
    Views:
    182
  4. Replies:
    2
    Views:
    229
  5. Indu
    Replies:
    9
    Views:
    351
Loading...

Share This Page