Select Category: <asp:DropDownList runat="server" ID="category" AutoPostBack="true" SelectMethod="GetCatalogCategories" AppendDataBoundItems="true" DataValueField="CategoryID" DataTextField="CategoryName"> <asp:ListItem Value="" Text="-select-"/> </asp:DropDownList> </td> <td> </td> <td> </td> </tr> <tr> <td> <asp:GridView ID="Catalog" runat="server" AutoGenerateColumns="False" ItemType="DataAccess.Product" AllowSorting="false" DataKeyNames="ProductID" SelectMethod="GetCatalog"> <Columns> <asp:BoundField DataField="ProductID" HeaderText="ProductID" SortExpression="ProductID" /> <asp:BoundField DataField="ProductName" HeaderText="Product Name" SortExpression="ProductName" /> <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" /> <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" SortExpression="CategoryID" /> <asp:TemplateField HeaderText="Category"> <ItemTemplate> <%#:Item.Category.CategoryName %> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Image"> <ItemTemplate> <img src="..Checkout/images/<%#:Item.ImagePath%>" width="20" height="25" border="1" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Select Products"> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> </ItemTemplate> </asp:TemplateField> </Columns>
List<product> tempIDList = new List<product>(); protected void Page_Load(object sender, EventArgs e) { } private MeatbyMobileContext _db = new MeatbyMobileContext(); public IQueryable<category> GetCatalogCategories() { return _db.Categories; } public IQueryable<product> GetCatalog([Control]int? category) { var query = _db.Products.Select(p => p); if (category.HasValue) { query = query.Where(p => p.CategoryID == category.Value); } return query; } protected void Button4_Click(object sender, EventArgs e) { for (int z = 0; z < Catalog.Rows.Count; z++) { MeatbyMobileContext db = new MeatbyMobileContext(); CheckBox chk = (CheckBox)Catalog.Rows[z].FindControl("CheckBox1"); if (chk.Checked) { int dKey = Convert.ToInt32( Catalog.DataKeys[z].Value); Product product = (from c in db.Products where c.ProductID.Equals(dKey) select c).SingleOrDefault(); tempIDList.Add(product ); } } GridView2.DataSource = tempIDList; GridView2.DataBind();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)