![]() |
|
|
|||||||
![]() |
ASP Net - Need to add Button to DataList |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Hello,
I need to add extra buttons to a datalist, but I don't know to add them to the control. I need to use the onCommand Functions, like OnUpdate, OnEdit, OnUpdate, OnCanel, Etc. I would like to do this VB.Net is that is can be done. Any help would be great, I have been trying to do this for a while and need help. Thanks in advance for any help, Jack Jack |
|
|
|
|
#2 |
|
Posts: n/a
|
Hi Jack,
I'm not really clear on what your problem is or what's not working for you. Perhaps you could elaborate? It the meantime, the code below (ASP.NET 2.0) inserts buttons into a datalist template. Let us know? Ken Microsoft MVP [ASP.NET] <%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Function CreateDataSource() As Data.DataTable Dim dt As New Data.DataTable Dim dr As Data.DataRow dt.Columns.Add(New Data.DataColumn _ ("IntegerValue", GetType(Int32))) dt.Columns.Add(New Data.DataColumn _ ("StringValue", GetType(String))) dt.Columns.Add(New Data.DataColumn _ ("CurrencyValue", GetType(Double))) dt.Columns.Add(New Data.DataColumn _ ("Boolean", GetType(Boolean))) Dim i As Integer For i = 0 To 5 dr = dt.NewRow() dr(0) = i dr(1) = "Item " + i.ToString() dr(2) = 1.23 * (i + 1) dr(3) = (i = 4) dt.Rows.Add(dr) Next i Return dt End Function Protected Sub Page_Load _ (ByVal sender As Object, ByVal e As System.EventArgs) If Not IsPostBack Then DataList1.DataSource = CreateDataSource() DataList1.DataBind() End If End Sub Sub btncmd(ByVal sender As Object, _ ByVal e As System.Web.UI.WebControls.CommandEventArgs) Label1.Text = e.CommandName End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:datalist id="DataList1" runat="server"> <itemtemplate> <asp:button id="Button1" runat="server" commandname="Add" oncommand="btncmd" text="Button" /> <asp:button id="Button2" runat="server" commandname="Edit" oncommand="btncmd" text="Button" /> <asp:button id="Button3" runat="server" commandname="Delete" oncommand="btncmd" text="Button" /><br /> <%#DataBinder.Eval(Container, "DataItem.StringValue")%> </itemtemplate> </asp:datalist> <asp:label id="Label1" runat="server" text=""></asp:label></div> </form> </body> </html> "Jack" <> wrote in message news:... > Hello, > > I need to add extra buttons to a datalist, but I don't know to add them to > the control. I need to use the onCommand Functions, like OnUpdate, > OnEdit, OnUpdate, OnCanel, Etc. I would like to do this VB.Net is that is > can be done. Any help would be great, I have been trying to do this for a > while and need help. > > Thanks in advance for any help, > > Jack > Ken Cox - Microsoft MVP |
|
|
|
#3 |
|
Posts: n/a
|
Well, add a Button Control to the template just like you would any other
Control. Then set the CommandName property of the Button. Depending on what CommandName you chose, one of the following events will be triggered when the button is clicked, depending on the value of CommandName: "edit" EditCommand "update" UpdateCommand "cancel" CancelCommand "delete" DeleteCommand "item" ItemCommand You can then determine which Item's button was clicked by using properties such as e.Item.ItemIndex. The Button also contains an optional CommandArgument property which is passed as well (if you use this property you will probably assign it a value in the ItemDataBound event). The e parameter, which is passed to the eventhandler, also contains several other properties. For more info, see the documentation or for a specific question feel free to ask. (Don't worry, it took me a while to figure this out also) Good Luck! -- Nathan Sokalski http://www.nathansokalski.com/ "Jack" <> wrote in message news:... > Hello, > > I need to add extra buttons to a datalist, but I don't know to add them to > the control. I need to use the onCommand Functions, like OnUpdate, > OnEdit, OnUpdate, OnCanel, Etc. I would like to do this VB.Net is that is > can be done. Any help would be great, I have been trying to do this for a > while and need help. > > Thanks in advance for any help, > > Jack > Nathan Sokalski |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Don't want to load the page everytime when I clicked on any ImageButton in DataList | tapasmahata | Software | 0 | 01-18-2008 08:45 AM |
| How do I reference a radio button in a datalist control | aspnetNewbie | General Help Related Topics | 0 | 04-30-2007 05:49 PM |
| How do find out if a button was clicked before the textchanged event of textbox fires | Jack | General Help Related Topics | 0 | 10-27-2006 10:19 AM |
| Re: Faulty PC power button | WinXP_Powered | A+ Certification | 5 | 03-09-2006 07:51 AM |
| Re: Faulty PC power button | Christopher Range | A+ Certification | 0 | 02-25-2006 12:02 AM |