private void GenerateControls() { ArrayList menuList = ConnectionClass.GetMenuByType("%"); foreach (Menu menu in menuList) { Panel menuPanel = new Panel(); Image image = new Image { ImageUrl = menu.image, CssClass = "ProductsImage" }; Literal literal = new Literal { Text = "<br />" }; Literal literal2 = new Literal { Text = "<br />" }; Label lblName = new Label { Text = menu.name, CssClass = "ProductsName" }; Label lblPrice = new Label { Text = String.Format("{0:0.00}", menu.price + "<br />"), CssClass = "ProductsPrice" }; TextBox textBox = new TextBox { ID = menu.id.ToString(), CssClass = "ProductsTextBox", Width = 60, Text = "0" }; RegularExpressionValidator regex = new RegularExpressionValidator { ValidationExpression = "^[0-9]*", ControlToValidate = textBox.ID, ErrorMessage = "Please enter a number." }; menuPanel.Controls.Add(image); menuPanel.Controls.Add(literal); menuPanel.Controls.Add(lblName); menuPanel.Controls.Add(literal2); menuPanel.Controls.Add(lblPrice); menuPanel.Controls.Add(textBox); menuPanel.Controls.Add(regex); pnlProducts.Controls.Add(menuPanel); } }
private void FillPage() { ArrayList menuList = new ArrayList(); if (!IsPostBack) { menuList = ConnectionClass.GetMenuByType("%"); } else { menuList = ConnectionClass.GetMenuByType(DropDownList1.SelectedValue); } StringBuilder sb = new StringBuilder(); foreach (Menu menu in menuList) { sb.Append(string.Format(@"<table class='menuTable'> <tr> <th rowspan='3' width='150px'><img runat='server' src='{3}' /></th> <th width='50px'> Name:</th> <td>{0}</td> <tr> <tr> <th>Type:</th> <td>{1}<td> <tr> <tr> <th>Price:</th> <td>{2} Rs<td> <tr> </table>", menu.name, menu.type, menu.price, menu.image)); lblOutput.Text = sb.ToString(); } }