如何使用相关表外键填充下拉列表项。 [英] How to fill dropdown list items with a related table foreign key.

查看:110
本文介绍了如何使用相关表外键填充下拉列表项。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在开发一个电子商务网站来学习ASP.Net和MVC。我有超过10个彼此相关的表。



基表是列Id(PK)Name,Price,Category_Id(FK)和Brand_Id(FK)

另一张表是分类表,其中包含列Id(PK)和Category_Name,

最后一张表是品牌表,其中包含列Id(PK)和Brand_Name 。(还有更多的表但与此问题无关)



我构建了运行CRUD操作的类。



问题在于;我正在尝试添加带有Web表单的产品。我有姓名和价格的文本框,我也有类别和品牌的下拉列表。下面的代码显示了我的ProducsBLL Insert方法。



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.

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();
        }





及以下代码显示我的PL添加代码背后的产品代码。



and below code shows my PL Add product code behind codes.

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);
}





第一个问题:如何将项目列为类别名称和品牌名称。 />
第二个问题:我如何获得所选类别和品牌的ID,然后将其添加到产品表中。



感谢您的考虑。 />
Emre。



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.

推荐答案

尝试此链接。它可以帮助您加载下拉列表并将选定的ID发布到操作结果

http://fromjami.wordpress.com/2013/09/17 / loading-dropdownlist-in-asp-net-mvc / [ ^ ]

希望这有帮助
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


这篇关于如何使用相关表外键填充下拉列表项。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆