Click here to Skip to main content
15,899,020 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone,

I am developing an e-commerce web site to learn ASP.Net and MVC. I have more than 10 tables that are in relation each other.

The base table is products with the columns Id(P.K)Name, Price, Category_Id(F.K) and Brand_Id(F.K)
The other table is Categories table with the columns Id(PK)and Category_Name,
The lasttable is Brands table with the columns Id(PK)and Brand_Name.(And more tables but not related about this question)

I have constructed the class that operates CRUD operations.

The problem is that; I am trying to add a product with a web form. I have textboxes for Name and price and also I have dropdownlists for Category and Brand. Below code show my ProducsBLL Insert method.

C#
Urun _Urun = new Urun
            {
                Adi = _Adi,
                Adet = _Adet,
                Fiyat = _Fiyat,
                Garanti = _Garanti,
                KargoDurumu = _KargoDurumu,
                AnaResim = _AnaResim,
                İcerik = _Icerik,
                Kategori_Id = _KategoriId,
                Marka_Id = _MarkaId,
            };
            db.Uruns.InsertOnSubmit(_Urun);
              db.SubmitChanges();
        }


and below code shows my PL Add product code behind codes.
C#
protected void btnEkle_Click(object sender, EventArgs e)
{
    UrunBLL _Urun = new UrunBLL();
     if (cbTavsiyemi.Checked == true)
    {
        statusTavsiye = true;
    }
    else if (cbTavsiyemi.Checked == false)
    {
        statusTavsiye = false;
    }
    if (cbKargo.Checked == true)
    {
        statusKargo = true;
    }
    else if (cbTavsiyemi.Checked == false)
    {
        statusKargo = false;
    }
    if (Convert.ToInt32(DropDownList1.SelectedItem.Value) == 1)
    {
        GarantiSure = Convert.ToInt32(TextBox1.Text);
    }
    else if (Convert.ToInt32(DropDownList1.SelectedItem.Value) == 0)
    {
        GarantiSure = 0;
    }

   _Urun.Ekle(txtUrunAd.Text, Convert.ToInt32(txtUrunAdet.Text), Convert.ToInt32(txtMarkaFiyat.Text),  GarantiSure,statusKargo, "yeni.jpg", txtUrunIcerik.Text, DropDownList2.SelectedIndex, DropDownList3.SelectedIndex);
}


First question: How can I list the items as Category names and Brand names.
Second question: How can I get the selected category and brand's id, then add them in product table.

Thanks for your consideration.
Emre.
Posted

1 solution

Try this link.It help you to load dropdown and post selected id to action result
http://fromjami.wordpress.com/2013/09/17/loading-dropdownlist-in-asp-net-mvc/[^]
Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900