c# - How to show corresponding value of a calculated field through html query string to another page -
i'm working on shopping cart functionality allows users add items shopping cart(via add cart button.) have specials page members discounted price items. have passed id(database) , sales price (calculated value) specials page add cart page.
i couldnt post images because dont have reputations here url looks like:
http://localhost:51231/legobits/shopping/shoppingcartitem.aspx?id=1&salesprice=0.89
you can see url getting values id , salesprice page, , i'm having trouble showing salesprice value in datalist of current page.
here code shoppingcartitem.aspx
<asp:datalist id="datalist1" runat="server" horizontalalign="center" datakeyfield="id" itemstyle-horizontalalign="left" datasourceid="sqldatasource1"> <itemtemplate> <asp:image id="image1" runat="server" imageurl='<%# eval("thumbnail", "{0}") %>' /> <asp:label id="pictureurllabel" runat="server" text='<%# eval ("thumbnail") %>' visible="false"></asp:label> <br /> <strong style="text-align: left;">name: </strong> <asp:label id="namelabel" runat="server" text='<%# eval("name") %>' /> <br /> <strong style="text-align: left;">model: </strong> <asp:label id="modellabel" runat="server" text='<%# eval("model") %>'></asp:label> <br /> <strong style="text-align: left;">ages: </strong> <asp:label id="ageslabel" runat="server" text='<%# eval("ages") %>'></asp:label> <br /> <strong style="text-align: left;">price: </strong> $ <asp:label id="pricelabel" runat="server"></asp:label> <br /> <br /> <asp:imagebutton imageurl="../images/addtocart.jpg" id="button1" runat="server" onclick="button1_click" /> </itemtemplate> </asp:datalist>
and code behind:
public partial class shopping_shoppingcartitem : basepage { protected void page_load(object sender, eventargs e) { string saleprice = request.querystring["sales price"]; string price = request.querystring["price"]; if (roles.isuserinrole("member")) { ((label)datalist1.controls[0].findcontrol("pricelabel")).text = saleprice; } else { ((label)datalist1.controls[0].findcontrol("pricelabel")).text = price; } }
the pricelabel should show salesprice value passed querystring page. please me out. in advance!!!
please try below code snippet.
aspx
<body> <form id="form1" runat="server"> <div> <asp:datalist id="datalist1" runat="server" horizontalalign="center" datakeyfield="id" itemstyle-horizontalalign="left"> <itemtemplate> <asp:label id="label1" runat="server" text='<%# eval("name") %>'></asp:label> <asp:label id="pricelabel" runat="server"></asp:label> </itemtemplate> </asp:datalist> </div> </form> </body>
aspx.cs
protected void page_load(object source, system.eventargs e) { dynamic data = new[] { new { id = 1, name ="name_1"} }; datalist1.datasource = data; datalist1.databind(); } protected void page_prerender(object source, system.eventargs e) { string saleprice = request.querystring["salesprice"]; ((label)datalist1.controls[0].findcontrol("pricelabel")).text = saleprice; }
update 1
aspx
<asp:datalist id="datalist1" runat="server" horizontalalign="center" datakeyfield="id" itemstyle-horizontalalign="left"> <itemtemplate> <asp:label id="label1" runat="server" text='<%# eval("name") %>'></asp:label> <asp:label id="pricelabel" runat="server" text='<%# eval("salesprice") %>' ></asp:label> </itemtemplate> </asp:datalist>
aspx.cs
protected void page_load(object source, system.eventargs e) { dynamic data = new[] { new { id = 1, name ="name_1", salesprice = 10.00} }; datalist1.datasource = data; datalist1.databind(); } protected void page_prerender(object source, system.eventargs e) { if (request.querystring["salesprice"] != null && !string.isnullorempty(request.querystring["salesprice"])) { string saleprice = request.querystring["salesprice"]; ((label)datalist1.controls[0].findcontrol("pricelabel")).text = saleprice; } }
let me know if concern.
Comments
Post a Comment