Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "adding an event for my btnDelete in repeater" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »
 
LinkBack Thread Tools Display Modes
  #1  
Old July 11th, 2008, 07:04 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default 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
Reply With Quote
Sponsored Links
  #2  
Old July 11th, 2008, 07:16 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

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.

Comments on this post
jmurrayhead agrees: You're getting good at this RR
Reply With Quote
The Following User Says Thank You to richyrich For This Useful Post:
Shem (July 11th, 2008)
  #3  
Old July 11th, 2008, 07:23 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

thanks a stack RR
Reply With Quote
  #4  
Old July 11th, 2008, 09:04 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

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
Reply With Quote
  #5  
Old July 11th, 2008, 09:08 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

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.

Comments on this post
richyrich agrees: Thanks for covering my mistake J...
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

Join our Folding team: DeveloperBarn Folding
Reply With Quote
The Following User Says Thank You to jmurrayhead For This Useful Post:
Shem (July 11th, 2008)
  #6  
Old July 11th, 2008, 09:14 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

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...
Reply With Quote
The Following User Says Thank You to richyrich For This Useful Post:
Shem (July 11th, 2008)
  #7  
Old July 11th, 2008, 09:15 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

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.
Reply With Quote
  #8  
Old July 11th, 2008, 09:20 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

thanks guys
Reply With Quote
  #9  
Old July 14th, 2008, 10:51 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

Hi

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

any ideas on why?

Shem
Reply With Quote
  #10  
Old July 14th, 2008, 11:06 AM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

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. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding ALL Button to Combo Box Northernlion Microsoft Access 3 July 8th, 2008 01:03 PM
adding numbers todd2006 JavaScript Programming 2 July 3rd, 2008 01:38 PM


All times are GMT -4. The time now is 08:19 PM.



Content Relevant URLs by vBSEO 3.2.0