如何插入附加下拉到数据库
How to insert appended dropdown into db
有人,这是一个很长的问题,所以请耐心听我说。所以我在表单中有一个下拉菜单来选择国家。有一个按钮将添加另一个下拉菜单,允许用户选择另一个国家。因此,如果用户选择添加另一个下拉列表,第二个下拉列表的值将不会被插入到数据库中,只会插入第一个下拉列表的值。下面是我的下拉菜单。
<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>
这里是链接存储过程的DAL
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)
那么为什么只有第一个下拉菜单被插入到表中呢?而不是第二个,第三个等等。如果我的解释不清楚,请随时提问。对不起,我的英语不好。
我想说objListOfItems
只被填充了一个值,但由于没有显示这只是一个有根据的猜测。
相关文章:
- 如何在数据库中插入日期
- 在数据库中插入数据后,无法重定向到 HTML 页面
- 我需要从单击事件在数据库中插入纬度和经度,但是当我单击时,我在数据库中得到了零值,而不是实际值
- 在数据库中插入之前获取UID主键
- 如何防止使用警报在数据库中插入重复数据
- 使用 JavaScript 中的文本框在数据库中插入记录
- 在一个数据库中插入多个文本框的数据
- 在数据库中插入纬度经度
- 如何在数据库中插入所有这些详细信息
- 在数据库中插入值和条形码扫描仪上的表单
- 从文本区域或分区在数据库中插入/显示可点击链接
- Rails在数据库中插入动态字段
- 使用MySQL,PHP和angular.js在数据库中插入数据数组
- 从node.js向mongoDB数据库中插入数据
- 如何使用jquery html和php在数据库中插入标签
- 使用JS在MySQL数据库中插入数据
- FullCalendar,Symfony 1.3在数据库中插入数据不需要表单
- 在数据库中插入clob数据或所有类型的文件存储
- 要在数据库中插入记录使用ajax和php
- 如何使用PHP在mysql数据库中插入图像和数据的源代码