asp.net - gridview cannot shown the item for shopping cart -
i creating shopping cart using asp.net
i following tutorial i've found online, http://www.asp.net/web-forms/tutorials/aspnet-45/getting-started-with-aspnet-45-web-forms/shopping-cart . i'm using gridview view cart after i've added in. however, don't know why, when add item, doesn't show in grid view.
i did calculation, adding items together. calculation show. it's item in grid view doesn't seems showing. can tell me what's wrong?
here error code i've received
@ system.web.ui.databinder.getpropertyvalue(object container, string propname) @ system.web.ui.databinder.eval(object container, string[] expressionparts) @ system.web.ui.databinder.eval(object container, string expression) @ system.web.ui.webcontrols.boundfield.getvalue(control controlcontainer) @ system.web.ui.webcontrols.boundfield.ondatabindfield(object sender, eventargs e) @ system.web.ui.control.ondatabinding(eventargs e) @ system.web.ui.control.databind(boolean raiseondatabinding) @ system.web.ui.control.databind() @ system.web.ui.control.databindchildren() @ system.web.ui.control.databind(boolean raiseondatabinding) @ system.web.ui.control.databind() @ system.web.ui.webcontrols.gridview.createrow(int32 rowindex, int32 datasourceindex, datacontrolrowtype rowtype, datacontrolrowstate rowstate, boolean databind, object dataitem, datacontrolfield[] fields, tablerowcollection rows, pageddatasource pageddatasource) @ system.web.ui.webcontrols.gridview.createchildcontrols(ienumerable datasource, boolean databinding) @ system.web.ui.webcontrols.compositedataboundcontrol.performdatabinding(ienumerable data) @ system.web.ui.webcontrols.gridview.performdatabinding(ienumerable data) @ system.web.ui.webcontrols.databoundcontrol.ondatasourceviewselectcallback(ienumerable data) @ system.web.ui.datasourceview.select(datasourceselectarguments arguments, datasourceviewselectcallback callback) @ system.web.ui.webcontrols.databoundcontrol.performselect() @ system.web.ui.webcontrols.basedataboundcontrol.databind() @ system.web.ui.webcontrols.gridview.databind() @ system.web.ui.webcontrols.basedataboundcontrol.ensuredatabound() @ system.web.ui.webcontrols.compositedataboundcontrol.createchildcontrols() @ system.web.ui.control.ensurechildcontrols() @ system.web.ui.control.prerenderrecursiveinternal() @ system.web.ui.control.prerenderrecursiveinternal() @ system.web.ui.control.prerenderrecursiveinternal() @ system.web.ui.control.prerenderrecursiveinternal() @ system.web.ui.control.prerenderrecursiveinternal() @ system.web.ui.page.processrequestmain(boolean includestagesbeforeasyncpoint, boolean includestagesafterasyncpoint)
gridview
<asp:gridview id="cartlist" runat="server" autogeneratecolumns="false" showfooter="true" gridlines="vertical" cellpadding="4" itemtype="mywebstore.models.cartitem" selectedmethod="getshoppingcartitems" cssclass="table table-striped table-bordered"> <columns> <asp:boundfield datafield="productid" headertext="id" sortexpression="productid" /> <asp:boundfield datafield="products.productname" headertext="name" /> <asp:boundfield datafield="products.unitprice" headertext="price (each)" dataformatstring="{0:c}" /> <asp:templatefield headertext="quantity"> <itemtemplate> <asp:textbox id="purchasequantity" runat="server" width="40" text="<%#: item.quantity %>"> </asp:textbox> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="item total"> <itemtemplate> <%#: string.format("{0:c}",((convert.todouble(item.quantity)) * convert.todouble(item.product.unitprice))) %> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="remove item"> <itemtemplate> <asp:checkbox id="remove" runat="server"></asp:checkbox> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
code-behind
protected void page_load(object sender, eventargs e) { using (shoppingcartactions usersshoppingcart = new shoppingcartactions()) { decimal carttotal = 0; carttotal = usersshoppingcart.gettotal(); if (carttotal > 0) { //display total lbltotal.text = string.format("{0:c}", carttotal); } else { labeltotaltext.text = ""; lbltotal.text = ""; shoppingcarttitle.innertext = "shopping cart empty"; } } } public list<cartitem> getshoppingcartitems() { shoppingcartactions actions = new shoppingcartactions(); return actions.getcartitems(); } protected void cartlist_selectedindexchanged(object sender, eventargs e) { }
cartitem class
public partial class cartitem { public string itemid { get; set; } public string cartid { get; set; } public int quantity { get; set; } public system.datetime datecreated { get; set; } public int productid { get; set; } public virtual product product { get; set; } }
Comments
Post a Comment