+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

Thread: adding an event for my btnDelete in repeater

  1. #1
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    adding an event for my btnDelete in repeater

    'Alo

    my repeater:
    Code:
    <asp:Repeater ID="rpProjectList" runat="server" OnItemDataBound="rpProjectList_OnItemDataBound">
                            <ItemTemplate>
                                <tr>
                                    <td><asp:TextBox ID="txtName" Text='<%#Eval("Name")%>' runat="server"></asp:TextBox></td>
                                    <td><asp:TextBox ID="txtProjectNumber" Text='<%#Eval("ProjectNumber")%>' runat="server"></asp:TextBox></td>
                                    <td><asp:TextBox ID="txtDecription" Text='<%#Eval("Description")%>' runat="server"></asp:TextBox></td>
                                    <td><asp:Label ID="lblCreatedBy" runat="server" Text='<%#Eval("CreatedBy")%>'></asp:Label> <asp:Label ID="lblCreatedDate" runat="server" Text='<%#Eval("TheDate")%>'></asp:Label></td>
                                    <td><asp:Label ID="lblEditedBy" runat="server" /> <asp:Label ID="lblEditedDate" runat="server" /></td>
                                    <td><asp:Button ID="btnDelete" runat="server" Text="Delete" /></td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
    
    Now I tried to write a sub for the click event of btnDelete, but i get errors saying thats there's more than one instance of btnDelete, in my repeater obviously?

    so how does one go about pulling it off, and at the same time how do i pass it
    the idkey of the record I want to delete, cuz if i use a HiddenField, I get the same error, more than one, blah blah blah

    Shem

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    In your repeater include OnItemCommand and on your button include CommandName and CommandArgument
    Code:
    <asp:Repeater ID="rpProjectList" runat="server" OnItemDataBound="rpProjectList_OnItemDataBound" OnItemCommand="rpProjectList_OnItemCommand" />
     
    <asp:button id="btnDelete" runat="server" Text="Delete" CommandName="Delete" CommandArgument='<%#Eval("Idkey")%>' />
    
    Then in your routine:-
    Code:
    sub rpProjectList_OnItemCommand(ByVal s As Object, ByVal e As RepeaterItemEventArgs)
    If e.CommandName="Delete" then
    'Delete record with id e.CommandArgument
     
    End Sub
    
    Hope that helps.

  3. #3
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    thanks a stack RR

  4. #4
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    I had to change it to this to get rid of the errors:
    Code:
    Sub rpProjectList_OnItemCommand(ByVal s As Object, ByVal e As RepeaterItemEventArgs)
            Dim btnDelete As String = e.Item.FindControl("btnDelete").ToString
            If btnDelete = "Delete" Then
                Response.Write(btnDelete)
            End If
        End Sub
    
    but getting this error:
    Code:
     Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
    
    Compiler Error Message: BC31143: Method 'Public Sub rpProjectList_OnItemCommand(s As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs)' does not have a signature compatible with delegate 'Delegate Sub RepeaterCommandEventHandler(source As Object, e As System.Web.UI.WebControls.RepeaterCommandEventArgs)'.
    
    Source Error:
    
    Line 31:                         <td colspan="2">Edited By</td>
    Line 32:                     </tr>
    Line 33:                     <asp:Repeater ID="rpProjectList" runat="server" OnItemDataBound="rpProjectList_OnItemDataBound" OnItemCommand="rpProjectList_OnItemCommand" />
    Line 34:                         <ItemTemplate>
    Line 35:                             <tr>
    
    
    Source File: C:\Inetpub\wwwroot\keithdesign\views\projects.aspx    Line: 33
    
    Where have i gone wrong

  5. #5
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,533
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Shem, that's all wrong..

    It should be like this:
    Code:
    Sub rpProjectList_OnItemCommand(ByVal s As Object, ByVal e As 
    RepeaterCommandEventArgs)
        If e.CommandArgument = "delete" Then
            'Do something...
        End If
    End Sub
    
    You then have to set the command buttons CommandArgument property equal to delete so the above code works.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  6. #6
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Sorry, my bad....I hadn't realised you'd posted again...I thought it was working...

    Shem, J is correct...It should have been e As RepeaterCommandEventArgs

    But I then think it should be if e.CommandName="delete" then and the CommandArgument should be your Idkey.

    I'm sure that should work...

  7. #7
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,533
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Yeap, RR is right. I wasn't paying attention to what I was doing. CommandName would tell us the action to perform and the CommandArgument tells us what record to peform it on.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  8. #8
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    thanks guys

  9. #9
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    Hi

    unfortunately nothing works, inside the IF statement I put a response.write
    and nothing writes to the screen

    any ideas on why?

    Shem

  10. #10
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,382
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Shem;
    Resposne.Write is probably not the best way to debug ASP.NET code. Can you set a breakpoint on the first statement in the event handler (you ARE using something like VWD or VS, right)? If you BP hits, you know the event handler is being fired, and you can example the e variable and ensure it has what you think it has. The code posted here (as corrected) should work. Also, post-up what you have now for a lookie.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Adding ALL Button to Combo Box
    By Northernlion in forum Microsoft Access
    Replies: 3
    Last Post: July 8th, 2008, 02:03 PM
  2. adding numbers
    By todd2006 in forum JavaScript Programming
    Replies: 2
    Last Post: July 3rd, 2008, 02:38 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

SEO by vBSEO