-
Oct 2nd, 2009, 09:53 AM
#1
Thread Starter
Frenzied Member
Add button in listview
Hi,
I would like to know how i can easly add a button to my listview control.
Thanks
-
Oct 2nd, 2009, 09:58 AM
#2
Thread Starter
Frenzied Member
Re: Add button in listview
ok, i was able to add a button with this line of code.
vb Code:
<asp:Button ID="Button1" runat="server" CommandName="Edit" Text="Editor" />
but now i would like to know where i can edit the command for this button.
thx
-
Oct 2nd, 2009, 10:06 AM
#3
Re: Add button in listview
Hey,
I think I am correct in saying that it is the ItemCommand of the ListView that you need to use:
http://msdn.microsoft.com/en-us/libr...emcommand.aspx
Gary
-
Oct 2nd, 2009, 10:15 AM
#4
Thread Starter
Frenzied Member
Re: Add button in listview
Hi,
ok, is there another way to add a button and write the code for than ItemCommand ?
thx
-
Oct 2nd, 2009, 10:22 AM
#5
Re: Add button in listview
Hey,
Why would you need another way? What is wrong with this way?
Gary
-
Oct 2nd, 2009, 11:16 AM
#6
Thread Starter
Frenzied Member
Re: Add button in listview
Hi,
Well, i wasn't able to make the code run correctly. I used the example to work with my code, but it's not working
-
Oct 2nd, 2009, 11:19 AM
#7
Re: Add button in listview
Hey,
Can you post the code that you tried? This is definitely the correct technique to use, so it is just a case of getting it to work.
Did you create the entire example code that was given? This is always a good place to start. It will let you see how things work, and you can build on it from there.
Gary
-
Oct 2nd, 2009, 11:32 AM
#8
Thread Starter
Frenzied Member
Re: Add button in listview
Well, the problem i'm having is, it's showing the msgbox whenever any button is clicked.
vb Code:
<asp:ListView ID="ListView8" runat="server" DataKeyNames="id" DataMember="DefaultView" DataSourceID="website" OnItemCommand="ListView8_OnItemCommand" InsertItemPosition="LastItem" style="text-align: left"> <ItemTemplate> <tr style="background-color: #FFFBD6;color: #333333;"> <td> <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" /> <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /> <asp:Button ID="Button1" runat="server" CommandName="OnItemCommand" Text="Editor" />
Protected Sub ListView8_OnItemCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs)
MsgBox("hi")
End Sub
-
Oct 2nd, 2009, 11:36 AM
#9
Re: Add button in listview
Hey,
That isn't how the CommandName is meant to be used. Did you read the documentation that I linked to?
You specify the CommandName for the button, in your case Edit, and then in the ItemCommand EventHandler, you check to see what the CommandName is, and then you take the appropriate action.
Gary
-
Oct 2nd, 2009, 11:55 AM
#10
Thread Starter
Frenzied Member
Re: Add button in listview
:S still i can get it run, it's showing the msg box for all the buttons
-
Oct 2nd, 2009, 02:57 PM
#11
Re: Add button in listview
Change
<asp:Button ID="Button1" runat="server" CommandName="OnItemCommand" Text="Editor" />
to
<asp:Button ID="Button1" runat="server" CommandName="MET0555" Text="Editor" />
Change the RowCommand event to
vb Code:
Protected Sub ListView8_OnItemCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs) If e.CommandName = "MET0555" Then MsgBox("hi") End If End Sub
The CommandName is a property you use in the RowCommand event to distinguish between the various buttons being clicked
-
Oct 3rd, 2009, 03:05 AM
#12
Re: Add button in listview
Hey,
This is what I was trying to say, but obviously didn't say it well enough. I thought the MSDN sample said it all, but obviously not.
Gary
-
Nov 1st, 2013, 03:19 AM
#13
Addicted Member
Re: Add button in listview
Good day all,
I know this is a bit out-dated, but using the prescribed method is causing errors in VS2012 & IE10. Any advice?
Thanks in advance!
-
Nov 1st, 2013, 03:55 AM
#14
Addicted Member
Re: Add button in listview
Apologies all - my bad (neglected to manage post-back).
Best regards.
-
Nov 4th, 2013, 02:20 AM
#15
Re: Add button in listview
Wow, this is an old thread Happy to hear that it was useful to you know!
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|