Я показываю категории в выпадающем списке для добавления продуктов. Когда продукт будет добавлен, вам нужно будет выбрать категорию и создать продукт или обновить предыдущий продукт.
Но моя проблема в том, что я получаю следующую ошибку:
Нет сопоставления для типа объекта
System.Web.UI.WebControls.DropDownList для известного управляемого поставщика
родной тип.
Диаграмма базы данных:

ASPX:.
<p>Kategori</p>
<asp:DropDownList ID="DDCategories" runat="server" AutoPostBack="True">
</asp:DropDownList>
ASPX.CS:.
protected void Page_Load(object sender, EventArgs e)
{
//Dropdown Category Names From DB
if (!IsPostBack)
{
string sConstr = ConfigurationManager.ConnectionStrings["LLcateringConnectionString"].ConnectionString;
SqlConnection Conn = new SqlConnection(sConstr);
DataTable dt = new DataTable("tbl");
using (Conn)
{
Conn.Open();
SqlCommand comm = new SqlCommand("SELECT Name FROM Category", Conn);
SqlDataAdapter da = new SqlDataAdapter(comm);
da.Fill(dt);
}
DDCategories.DataSource = dt;
DDCategories.DataTextField = "Name";
DDCategories.DataBind();
}
}
protected void BtnUpdateOrCreate_Click(object sender, EventArgs e)
{
// Text in fields has to exist, if they are requierd
if (!string.IsNullOrWhiteSpace(TxtName.Text) /*&&
!string.IsNullOrWhiteSpace(TxtDescription.Text)*/)
{
// New the DataAccess and have all the parameteres here
DataAccess dataAccess = new DataAccess();
dataAccess.AddParameter("@Name", TxtName.Text);
dataAccess.AddParameter("@Category_ID", DDCategories);
dataAccess.AddParameter("@Description", TxtDescription.Text.ToNewline(false));
dataAccess.AddParameter("@UnitPrice", TxtPrice.Text);
dataAccess.AddParameter("@DiscountUnitPrice", TxtUnitDiscount.Text);
if (isCreate)
{
// Insert query
dataAccess.Execute(@"INSERT INTO [Product] ([Name], [Category_ID], [UnitPrice], [DiscountUnitPrice], [Description])
VALUES (@Name, @Category_ID, @UnitPrice, @DiscountUnitPrice, @Description)
INNER JOIN dbo.Product ON dbo.Category.ID = dbo.Product.Category_ID
ORDER BY [Name]
WHERE id = @id");
}
else
{
// Update query
dataAccess.AddParameter("@id", MenuID);
dataAccess.Execute(@"UPDATE [Product]
SET [Name] = @Name, [Category_ID] = @Category_ID, [UnitPrice] = @UnitPrice, [DiscountUnitPrice] = @DiscountUnitPrice, [Description] = @Description
WHERE id = @id");
//UPDATE [Product]
//SET [Name] = @Name, [Category_ID] = @Category_ID, [UnitPrice] = @UnitPrice, [DiscountUnitPrice] = @DiscountUnitPrice, [Description] = @Description
//INNER JOIN dbo.Product ON dbo.Category.ID = dbo.Product.Category_ID
//ORDER BY [Name]
//WHERE id = @id");
}
// Redirects to list
Response.Redirect(Request.Url.AbsolutePath);
}
else
LitStatus.Text = "Hey så indtast da noget!";
}