New test.
[mono.git] / mcs / class / System.Web / Test / standalone / datalist / datalist-style-edit.aspx
1 <!-- Inspired by bug 49020 -->
2 <%@ Page language="c#" Debug="true" %>
3 <%@ Import Namespace="System.Data" %>
4 <html>
5         <head>
6                 <script runat="server">
7                 DataSet ds;
8                 private void Page_Load (object sender, EventArgs e)
9                 {
10                         PopulateList();
11                 }
12                 
13                 private void PopulateList()
14                 {
15                         if (IsPostBack) {
16                                 ds = (DataSet) ViewState ["ds"];
17                                 return;
18                         } else {
19                                 ds = new DataSet ();
20                                 ds.ReadXml (new System.IO.StringReader (@"
21 <DataSet>
22         <Stocks Company='Novell Inc.'     Symbol='NOVL' Price='6.14'   />
23         <Stocks Company='Microsoft Corp.' Symbol='MSFT' Price='25.92'  />
24         <Stocks Company='Google'          Symbol='GOOG' Price='291.60' />
25 </DataSet>
26 "));
27                                 ViewState ["ds"] = ds;
28                         }
29
30                         DataList1.GridLines = GridLines.Both;
31                         DataList1.DataSource = ds;
32                         DataList1.DataBind();
33                 }
34         
35                 private void EditCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
36                 {
37                         DataList1.EditItemIndex = e.Item.ItemIndex;
38                         DataList1.DataSource = ds;
39                         DataList1.DataBind();   
40                 }
41                 
42                 private void UpdateCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
43                 {
44                         
45                         string name = ((TextBox)e.Item.FindControl("edit_name")).Text;
46                         ds.Tables[0].Rows [DataList1.EditItemIndex]["Company"] = name;
47                         DataList1.EditItemIndex = -1;
48                         ViewState ["ds"] = ds;
49                         DataList1.DataSource = ds;
50                         DataList1.DataBind();
51                 }
52                 </script>
53         </head>
54         <body>
55                 <form runat="server">
56                         <asp:datalist
57                                 runat="server"
58                                 id="DataList1"
59                                 OnEditCommand="EditCommand"
60                                 OnUpdateCommand="UpdateCommand"
61                                 RepeatColumns="2"
62                                 RepeatDirection="vertical">
63                                 <ItemTemplate>
64                                         <asp:label runat="server" Text='<%# DataBinder.Eval (Container.DataItem, "Company") %>' />
65                                         <asp:LinkButton Runat="server" CommandName="Edit" Text="Edit" />
66                                 </ItemTemplate>
67                                 <EditItemTemplate>
68                                                 <asp:textbox id="edit_name" text='<%# DataBinder.Eval(Container.DataItem, "Company") %>' runat="server" />
69                                                 <asp:linkbutton runat="server" commandname="Update" text="Update" />
70                                 </EditItemTemplate>
71                         </asp:datalist>
72                 </form>
73         </body>
74 </html>