2017-06-14 3 views
0
code For It 

され持っています私は、カテゴリのドロップダウン enter image description hereは私がに応じてカテゴリの製品sholud負荷を選択したときにだけ必要がある2つのドロップダウンカテゴリと製品を、私は二つのDropdownlistsカテゴリーの一つと私はAAのITMフォームのドロップダウンカテゴリにその後、製品のドロップダウンリストを選択する第二の製品を作っ

public partial class Product 
     { 
      public int ProductID { get; set; } 
      public int CategoryID { get; set; } 
      public string ProductName { get; set; } 
     } 
    } 
    public partial class Category 
     { 
      public int CategoryID { get; set; } 
      public string CategoryName { get; set; } 
      public virtual ICollection<Product> Products { get; set; } 
     } 

    public ActionResult Create() 
      { 
       ViewBag.vbCategoryList = new SelectList(db.Categories.Select(x => new { Value = x.CategoryID, Text = x.CategoryName}), "Value", "Text"); 
       ViewBag.vbProductList = new SelectList(db.Products.Select(x => new { Value = x.ProductID, Text = x.ProductName }), "Value", "Text"); 
       return View(); 
      } 

    <table class="table"> 
       <tr> 
        <td>Category</td> 
        <td>Product</td> 
        <td>Quantity</td> 
        <td>Rate</td> 
        <td>&nbsp;</td> 
       </tr> 
       <div id="Tbody1"> 
       <tr class="mycontainer" id="mainrow"> 
        <td> 
         @Html.DropDownListFor(model => model.CategoryID, (SelectList)ViewBag.vbCategoryList, "Select One", htmlAttributes: new { @class = "form-control" }) 
        </td> 
        <td>` 
         @Html.DropDownListFor(model => model.ProductID, (SelectList)ViewBag.vbProductList, "Select One", htmlAttributes: new { @class = "form-control" }) 
        </td> 
        <td></td> 
        <td> 
         <input type="text" id="rate" class="rate form-control" /> 
        </td> 
        <td> 
         <input type="button" id="AddMore" style="width:80px" value="AddMore" class="btn btn-success /"> 
        </td> 
       </tr> 
       </div> 

から選択したカテゴリに応じて製品を表示すべきである[ここに画像の説明を入力します] [2]

+0

を与えたいとhttps://stackoverflow.com/questions/12258839/populate-dropdown-list-based-on-another-dropdown-list ..Must顔をして、それを変更することができますこれで – Dhawal

答えて

0

をページロードの1 thing..Whenは、カテゴリドロップダウンを記入してくださいこの

  if (!IsPostBack)//in pageload 
      {    
       objENT = new ENT(); 
       objENT.ProcType = "ZONEMASTER"; 
       DataSet dsLoad = BLL.CdInput(objENT); 
       FillCombo(dsLoad.Tables[0], ddlZone);    
      } 
void FillCombo(DataTable dt, DropDownList ddl)//outside pageload 
     { 
      ddl.DataSource = dt; 
      ddl.DataTextField = "Name"; 
      ddl.DataValueField = "ID"; 
      ddl.DataBind(); 

     } 

にストアドプロシージャを使用して、その後

protected void ddlZone_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     objENT.ProcType = "procedure"; 
     objENT.strZone = ddlZone.SelectedItem.Value; 
     DataSet dsLoad = BLL.CdInput(objENT); 
     FillCombo(dsLoad.Tables[0], ddlStore); 

    } 

にドロップダウンの値を取得し、データベースにDropdown.SelectedItem.Valueを送信して製品を得るに応じ これは私が使用した概念であり、 uがuは はそれを試し:)

関連する問題