2015-06-04 53 views
0

任何人,這是一個很長的問題,所以忍受着我。所以我有一個在我的表格下拉選擇國家。有一個按鈕可以添加另一個允許用戶選擇另一個國家的下拉菜單。因此,如果用戶選擇添加另一個下拉列表,則第二個值不會插入到數據庫中,只會插入第一個值。下面是我的下拉列表。如何在數據庫中插入附加下拉菜單

   <div class="editor-field" id="mb"> 
        Member Countries 


        <div id="jj"> 
         @Html.DropDownListFor(model => model.Memberc, ViewBag.lCountry as SelectList, "--select--", new { @id = "tid0" })<br /> 
        </div> 

下面

是按鈕添加下拉

   <div id="test"> 
       </div> 
       <input type='button' value='Add' id='addButton'> 

然後我們有做的工作,以克隆下拉列表中的JavaScript。

<script> 
$(document).ready(function() 
    { 
     $("#addButton").click(function() { 
      var elements = $("select[id!='template']"); 
      var newElement = $("#jj").clone(true); 
      var count = elements.length; 
      if (count > 8) { 
       alert('no more dropdowns'); 
      } 
      else { 
       newElement.attr('id', count);//rename new element so that it refers to  distinguished object instead of cloned object 
       $("#test").append(newElement); 
      } 
     }); 

     $("#removeButton").live("click", function() { 
      $(this).parents("div.jj:first").remove(); 
      return false; 
     }); 
    }); 
</script> 

繼承人鏈接的存儲過程

public static ListOfItems CreateSchemeCInsert(ListOfItems objListOfItems) 
    { 
     SqlDataReader rdrDataAccess = null; 
     ListOfItems objListOfItemsDetails = null; 
     SqlConnection database = new SqlConnection(MyCOODataConn.MyCOOConnectionString); 

     //Insert Data in DB 
     database.Open(); 
     SqlCommand databaseCmd = new SqlCommand("SP_APP_Specific_SchemeCInsert", database);//name SP in database 
     databaseCmd.CommandType = CommandType.StoredProcedure; 
     databaseCmd.Parameters.Add(new SqlParameter("@User_scheme_master_id", objListOfItems.msi)); 
     databaseCmd.Parameters.Add(new SqlParameter("@Country_id", objListOfItems.Memberc)); 


     rdrDataAccess = databaseCmd.ExecuteReader(); 
     objListOfItemsDetails = new ListOfItems(); 

     return objListOfItemsDetails; 

    } 

和我的存儲過程看起來非常正常

Insert into [dbo].[APP_Specific_Scheme_Country] 
(user_scheme_master_id, country_id) 
Values (@schemeid,@Country_id) 

那麼,爲什麼只有第一個下拉列表插入到表中的DAL?而不是第二,第三等等。如果我的解釋不清楚,請隨時提問。對不起英語不好。

回答

0

我會說,objListOfItems只是填充一個值,但因爲沒有顯示它只是一個受過良好教育的猜測。

相關問題