Hi,
I would like to know how i can easly add a button to my listview control.
Thanks
Printable View
Hi,
I would like to know how i can easly add a button to my listview control.
Thanks
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
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
Hi,
ok, is there another way to add a button and write the code for than ItemCommand ?
thx
Hey,
Why would you need another way? What is wrong with this way?
Gary
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
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
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" />
Quote:
Protected Sub ListView8_OnItemCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs)
MsgBox("hi")
End Sub
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
:S still i can get it run, it's showing the msg box for all the buttons
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
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
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!
Apologies all - my bad (neglected to manage post-back).
Best regards.
Wow, this is an old thread :) Happy to hear that it was useful to you know!
Gary