---
title: "Drop Down List in ASP.NET for C#. Column 'Colour' does not belong to table"  
description: "Drop Down List in ASP.NET for C#. Column 'Colour' does not belong to table"  
author: "Elena Glibart"  
published: 2014-11-26  
updated: 2014-11-27  
canonical: https://www.mindstick.com/forum/12694/drop-down-list-in-asp-dot-net-for-c-sharp-column-colour-does-not-belong-to-table  
category: "asp.net"  
tags: ["c#", "dropdown", "listbox"]  
reading_time: 3 minutes  

---

# Drop Down List in ASP.NET for C#. Column 'Colour' does not belong to table

<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](https://www.mindstick.com/forum/2057/access-textbox-in-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 from colour">

</asp:SqlDataSource>

<asp:[DropDownList](https://www.mindstick.com/articles/324837/how-to-bind-dropdownlist-in-mvc-core-from-database-using-entity-framework) ID="DDListColour" runat="server"

DataSourceID="DSColour" DataTextField="colour_name"

[DataValueField](https://www.mindstick.com/forum/12846/dropdownlist-datavaluefield-in-asp-dot-net-c-sharp)="colour_id"

AppendDataBoundItems="true"

OnSelectedIndexChanged="colour_SelectedIndexChanged"

[AutoPostBack](https://www.mindstick.com/interview/2074/what-is-autopostback)="True" >

</asp:DropDownList>

<asp:SqlDataSource ID="DSSize" runat="server"

ConnectionString="<%$ ConnectionStrings:XXX %>"

ProviderName="<%$ ConnectionStrings:XXX.ProviderName %>"

SelectCommand="select size_id, size_name from 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](https://www.mindstick.com/articles/12753/imagebutton-in-android) ID="Button1" runat="server" CssClass="addcart" ImageUrl="~/Image/btn_buy.gif" />

</ItemTemplate>

</asp:Repeater>

</asp:Content>

Please find below the code for the [code behind](https://www.mindstick.com/forum/2199/call-javascript-s-function-from-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](https://www.mindstick.com/forum/155717/define-partial-class-in-mvc) 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](https://www.mindstick.com/interview/808/what-is-a-data-source)=X;Persist Security Info=True;User ID=Y;Password=Z";

DSProduct.ProviderName = "System.Data.OracleClient";

DSProduct.SelectCommand = "SELECT * FROM Product WHERE 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;

for (i = 0; i < 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 I said I am having the following error (related to the 'Colour' column that is not recognised for some reason):

[Exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling) Details: System.ArgumentException: Column 'Colour' does not belong to 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 you in advance](https://answers.mindstick.com/qa/40482/why-was-1968-a-year-of-tension-and-turmoil-list-10-events-1-being-the-best-and-10-the-worst-thank-you-in-advance).

## Replies

### Reply by Anonymous User

I have found a solution, I have followed the hint given by Rick. However this causes another issue: that when you add a column below the if statement, the second time the code runs you will receive an error message because the column already exists. I have found a way around, that you can find below.

```
if (!flag_found){{   // This checks if the columns are there alreadyif (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{   // This generates the columns if they are not there alreadyLocalCart.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);}}}
```


---

Original Source: https://www.mindstick.com/forum/12694/drop-down-list-in-asp-dot-net-for-c-sharp-column-colour-does-not-belong-to-table

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
