[Mono-bugs] [Bug 76117][Blo] New - Datagrid command postback doesn't behave like on MS.NET

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Thu Sep 15 15:34:50 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by carlos at applianz.com.

http://bugzilla.ximian.com/show_bug.cgi?id=76117

--- shadow/76117	2005-09-15 15:34:50.000000000 -0400
+++ shadow/76117.tmp.12344	2005-09-15 15:34:50.000000000 -0400
@@ -0,0 +1,150 @@
+Bug#: 76117
+Product: Mono: Class Libraries
+Version: unspecified
+OS: GNU/Linux [Other]
+OS Details: Gentoo 64bit
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Blocker
+Component: Sys.Web
+AssignedTo: gonzalo at ximian.com                            
+ReportedBy: carlos at applianz.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Datagrid command postback doesn't behave like on MS.NET
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+When I have a command on a datagrid clicking on the button doesn't seem to
+post back to the command handler. 
+
+To reproduce it just copy this code into an aspx file and click on the TEST
+link, you should see the price printed on the top of the page. It seems to
+work fine on windows using mono but I have only tested it once on windows.
+
+<%@ Import Namespace="System.Data" %>
+<HTML>
+	<script language="C#" runat="server">
+
+    DataTable Cart;
+    DataView CartView;
+
+    ICollection CreateDataSource() {
+        DataTable dt = new DataTable();
+        DataRow dr;
+
+        dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
+        dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
+        dt.Columns.Add(new DataColumn("DateTimeValue", typeof(DateTime)));
+        dt.Columns.Add(new DataColumn("BoolValue", typeof(bool)));
+        dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
+
+        for (int i = 0; i < 9; i++) {
+            dr = dt.NewRow();
+            dr[0] = i;
+            dr[1] = "Item " + i.ToString();
+            dr[2] = DateTime.Now;
+            dr[3] = (i % 2 != 0) ? true : false;
+            dr[4] = 1.23 * (i+1);
+
+            dt.Rows.Add(dr);
+        }
+
+        DataView dv = new DataView(dt);
+        return dv;
+    }
+
+    void Page_Load(Object sender, EventArgs e) {
+    
+        if (Session["DG4_ShoppingCart"] == null) {
+            Cart = new DataTable();
+            Cart.Columns.Add(new DataColumn("Item", typeof(string)));
+            Cart.Columns.Add(new DataColumn("Price", typeof(string)));
+            Session["DG4_ShoppingCart"] = Cart;
+        }
+        else {
+            Cart = (DataTable)Session["DG4_ShoppingCart"];
+        }    
+        CartView = new DataView(Cart);
+        ShoppingCart.DataSource = CartView;
+        ShoppingCart.DataBind();
+
+        if (!IsPostBack) {
+            // need to load this data only once
+            MyDataGrid.DataSource= CreateDataSource();
+            MyDataGrid.DataBind();
+        }
+    }
+
+    void Grid_CartCommand(Object sender, DataGridCommandEventArgs e) {
+    
+        DataRow dr = Cart.NewRow();
+        Response.Write(e.Item.Cells[3].Text);
+        // e.Item is the row of the table where the command fired
+        // For bound columns the value is stored in the Text property of
+TableCell
+        TableCell itemCell = e.Item.Cells[2];
+        TableCell priceCell = e.Item.Cells[3];
+        string item = itemCell.Text;
+        string price = priceCell.Text;
+        
+        if (((LinkButton)e.CommandSource).CommandName == "AddToCart") {
+            dr[0] = item;
+            dr[1] = price;
+            Cart.Rows.Add(dr);
+        }
+        else {   //Remove from Cart
+        
+            CartView.RowFilter = "Item='"+item+"'";
+            if (CartView.Count > 0) {    
+                CartView.Delete(0);
+            }
+            CartView.RowFilter = "";
+        }
+        ShoppingCart.DataBind();
+
+    }
+
+
+	</script>
+	<body>
+		<h3><font face="Verdana">Using a ButtonColumn in DataGrid</font></h3>
+		<form id="Form1" runat="server">
+			<table cellPadding="5">
+				<tr valign="top">
+					<td>
+						<b>Product List</b>
+						<ASP:DataGrid id="MyDataGrid" runat="server" BorderColor="black"
+BorderWidth="1" CellPadding="3"
+							Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd"
+AutoGenerateColumns="false"
+							OnItemCommand="Grid_CartCommand">
+							<Columns>
+								<asp:ButtonColumn HeaderText="Add to cart" Text="Add"
+CommandName="AddToCart" />
+								<asp:ButtonColumn HeaderText="TEST" Text="TEST"
+CommandName="RemoveFromCart" />
+								<asp:BoundColumn HeaderText="Item" DataField="StringValue" />
+								<asp:BoundColumn HeaderText="Price" DataField="CurrencyValue"
+DataFormatString="{0:c}" ItemStyle-HorizontalAlign="right" />
+								<asp:BoundColumn HeaderText="Assembly required?"
+DataField="BoolValue" />
+							</Columns>
+						</ASP:DataGrid>
+					</td>
+					<td>
+						<b>Shopping Cart</b>
+						<ASP:DataGrid id="ShoppingCart" runat="server" BorderColor="black"
+BorderWidth="1" GridLines="Both"
+							ShowFooter="false" CellPadding="3" CellSpacing="0"
+Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" />
+					</td>
+				</tr>
+			</table>
+		</form>
+	</body>
+</HTML>


More information about the mono-bugs mailing list