Drop Down List in ASP.NET for C#. Column 'Colour' does not belong to table -


please find attached entire code .aspx file:

<asp:content id="content1" contentplaceholderid="headcontent" runat="server">  </asp:content> <asp:content id="content2" contentplaceholderid="leftcontent" runat="server"> </asp:content> <asp:content id="content3" contentplaceholderid="maincontent" runat="server"> <asp:sqldatasource id="dsproduct" runat="server"> </asp:sqldatasource> <asp:sqldatasource id="dssize" runat="server" > </asp:sqldatasource> <asp:repeater id="repeater1" runat="server" datasourceid="dsproduct"  onitemcommand="repeater1_itemcommand" >  <itemtemplate> <br /> <asp:image id="image1" runat="server"  imageurl='<%#eval("image2","~/image/{0}") %>'  height="230" width="230" cssclass="largeimage" />       <h3 style="color: #ffffff; font-weight: bold; "> <asp:label id="lname" runat="server" text='<%# eval("product_name")%>'> </asp:label> &nbsp; &nbsp;  <asp:label id="lprice" style="text-decoration: line-through;" runat="server"  text='<% # convert.todecimal(eval("price")).tostring("£#,##0.00") %>' font-size="small" forecolor = "blue" > </asp:label> <asp:label id="label4" runat="server" text=" £ " forecolor="red" backcolor="white"> </asp:label>  <asp:label id="lprice_disc" runat="server" text='<%# convert.todecimal(eval("discount_price")).tostring("#,##0.00") %>'  backcolor="white" forecolor = "red"> </asp:label>   <asp:label id="lid" runat="server" text='<%# eval("product_id") %>' visible="false"> </asp:label> </h4> <asp:sqldatasource id="dscolour" runat="server"  connectionstring="<%$ connectionstrings:xxx %>"  providername="<%$ connectionstrings:xxx.providername %>" selectcommand="select colour_id, colour_name colour"> </asp:sqldatasource> <asp:dropdownlist id="ddlistcolour" runat="server"  datasourceid="dscolour" datatextfield="colour_name"  datavaluefield="colour_id"  appenddatabounditems="true" onselectedindexchanged="colour_selectedindexchanged" autopostback="true"  > </asp:dropdownlist> <asp:sqldatasource id="dssize" runat="server"  connectionstring="<%$ connectionstrings:xxx %>"  providername="<%$ connectionstrings:xxx.providername %>" selectcommand="select size_id, size_name size_t"> </asp:sqldatasource> <asp:dropdownlist id="dropdownlistsize" runat="server"  datasourceid="dssize" datatextfield="size_name"  datavaluefield="size_id" autopostback="true"  > </asp:dropdownlist> <asp:label id="label1" runat="server" text='<%# eval("product_id") %>' visible="true"> </asp:label> <h5 style="color: #000000; font-weight: normal;"  >  <asp:label id="ldesc" runat="server" text='<%# eval("product_description")%>'  width="500" font-size="medium" font-bold="true"> </asp:label></h5>  <asp:imagebutton id="button1" runat="server"  cssclass="addcart" imageurl="~/image/btn_buy.gif" /> </itemtemplate> </asp:repeater>  </asp:content> 

please find below code code behind file:

using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using system.data;  public partial class product : system.web.ui.page { private string datavaluefield; private string colour; protected void page_load(object sender, eventargs e) { string pid = request.querystring["pid"]; dsproduct.connectionstring = "data source=x;persist security info=true;user id=y;password=z"; dsproduct.providername = "system.data.oracleclient"; dsproduct.selectcommand = "select * product product_id= '" + pid + "'";  }  protected void repeater1_itemcommand(object source, repeatercommandeventargs e) { string url = httpcontext.current.request.url.absoluteuri; boolean flag_found; int i; datatable localcart = new datatable(); localcart.columns.add("colour",typeof(string)); datarow dr;  session["cururl"] = url; if (session["username"] == null) response.redirect("login.aspx"); localcart = (datatable)session["cart"]; int localcartitemcount = (int)session["cartitemcount"]; decimal localcartamount = (decimal)session["cartamount"];   flag_found = false; (i = 0; < localcart.rows.count; i++) { if (localcart.rows[i]["id"].equals(((label)e.item.findcontrol("lid")).text.tostring())) { localcart.rows[i]["quantity"] = convert.toint32(localcart.rows[i]["quantity"]) + 1; localcart.rows[i]["subtotal"] = convert.toint32(localcart.rows[i]["quantity"]) * convert.todecimal(localcart.rows[i]["price"]); flag_found = true; break; } } if (!flag_found) { dr = localcart.newrow(); dr["id"] = ((label)e.item.findcontrol("lid")).text.tostring(); dr["name"] = ((label)e.item.findcontrol("lname")).text.tostring(); dr["price"] = convert.todecimal(((label)e.item.findcontrol("lprice_disc")).text.tostring()); dr["quantity"] = 1; dr["subtotal"] = convert.todecimal(dr["price"]); dr["colour"] = ((dropdownlist)e.item.findcontrol("ddlistcolour")).selectedvalue; localcart.rows.add(dr);  } localcartitemcount++; localcartamount += convert.todecimal(((label)e.item.findcontrol("lprice_disc")).text.tostring()); session["cart"] = localcart; session["cartamount"] = localcartamount; session["cartitemcount"] = localcartitemcount; response.redirect("cartdisp.aspx"); }  } 

like said having following error (related 'colour' column not recognised reason):

exception details: system.argumentexception: column 'colour' not belong table .

source error:

line 62: dr["quantity"] = 1; line 63: dr["subtotal"] = convert.todecimal(dr["price"]); line 64: dr["colour"] = ((dropdownlist)e.item.findcontrol("ddlistcolour")).selectedvalue; line 65: localcart.rows.add(dr);

thank in advance.

s

i have found solution, have followed hint given rick. causes issue: when add column below if statement, second time code runs receive error message because column exists. have found way around, can find below.

if (!flag_found) { {   // checks if columns there if (localcart.columns["colour"] != null && localcart.columns["size"] != null )  { dr = localcart.newrow(); dr["id"] = ((label)e.item.findcontrol("lid")).text.tostring(); dr["name"] = ((label)e.item.findcontrol("lname")).text.tostring(); dr["price"] = convert.todecimal(((label)e.item.findcontrol("lprice_disc")).text.tostring()); dr["quantity"] = 1; dr["subtotal"] = convert.todecimal(dr["price"]); dr["colour"] = ((dropdownlist)e.item.findcontrol("ddlistcolour")).selectedvalue; dr["size"] = ((dropdownlist)e.item.findcontrol("ddlistsize")).selectedvalue; localcart.rows.add(dr); } else {   // generates columns if not there localcart.columns.add("colour", typeof(string)); localcart.columns.add("size", typeof(string)); dr = localcart.newrow(); dr["id"] = ((label)e.item.findcontrol("lid")).text.tostring(); dr["name"] = ((label)e.item.findcontrol("lname")).text.tostring(); dr["price"] = convert.todecimal(((label)e.item.findcontrol("lprice_disc")).text.tostring()); dr["quantity"] = 1; dr["subtotal"] = convert.todecimal(dr["price"]); dr["colour"] = ((dropdownlist)e.item.findcontrol("ddlistcolour")).selectedvalue; dr["size"] = ((dropdownlist)e.item.findcontrol("ddlistsize")).selectedvalue; localcart.rows.add(dr); } } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -