JS 动态显示 获取下拉框的多个值

本文介绍了一个ASP.NET应用程序中实现下拉列表数据绑定的方法。通过后台代码展示了如何从数据库获取数据并填充到前端下拉列表中,同时实现了根据用户选择动态更新相关字段的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 <script type="text/javascript">
        function GetProcessVal(i, t) {
            document.getElementsByName("items[#index#].typeName")[i].value += t.value + ',';
        }
 </script>


后台代码:

 
static StringBuilder sbProcessingtype = null;


private
void getProcessingtype()
        {
           
if (null == sbProcessingtype)
            {
                sbProcessingtype
= new StringBuilder();
               
string str_Query = "select comoboxText  from  Bs_ComboBoxConfig  where comoboxID='15' order by comoboxValue asc";
                IList
<string> list = objComboBoxConfigRepository.ExecuteSQLReturnStr(str_Query);

                sbProcessingtype.Append(
"<select  onchange=\"GetProcessVal({0},this)\"   name=\"items[#index#].Processingtype\"  > <option value=\"\"></option>");
               
int count = list.Count;
               
for (int i = 0; i < count; i++)
                {
                    sbProcessingtype.Append(
"<option value=\"" + list[i] + "\">" + list[i] + "</option>");
                }
            }
        }

调用 :

 private string BindTable(IList<VOutProceManager> objList, bool isDeleted)
        {
            sbProcessingtype = null;
            getProcessingtype();//调用方法
            string strCalMethod = "";
            StringBuilder sb = new StringBuilder();
            int i = 0;
            string currentdate = DateTime.Now.ToString("yyyy-MM-dd");
            string PriceType = Convert.ToString(base.GetComboBoxConfig(15));
            foreach (VOutProceManager obj in objList)
            {
                sb.Append("<tr class=\"unitBox\">");
                if (isDeleted)
                    sb.Append("<td style='width:30px'  ><a class='btnDel' style='width:22px' target=\"ajaxTodo\" style=\"cursor:pointer\"  href=\"outProcessGL/OProcessRequisition/DelMaterialInfo?id=" + obj.Id + "&iscoper=" + obj.Isbom + "\" >删除</a></td>");
                else
                    sb.Append("");
                sb.Append("<input type=\"hidden\"   name=\"items[#index#].Id\"   submitName=\"items[" + i + "].Id\" value=\"" + obj.Id + "\" /> ");
                sb.Append("<input type=\"hidden\"   name=\"items[#index#].bomID\"   submitName=\"items[" + i + "].bomID\" value=\"" + obj.bomID + "\" /> ");
                sb.Append("<input type=\"hidden\"   name=\"items[#index#].Isbom\"   submitName=\"items[" + i + "].Isbom\" value=\"" + obj.Isbom + "\" /> ");
                sb.Append("<td  ><input class=\"textInput \"   size='15'   readonly=\"readonly\"  value=\"" + obj.mouldNo + "\"  > </td>");
                sb.Append("<td  ><input class=\"textInput \" size='9'   readonly=\"readonly\" name=\"items[#index#].partName\" submitName=\"items[" + i + "].partName\" value=\"" + obj.partName + "\"  > </td>");
                sb.Append("<td  ><input class=\"textInput \" size='3'   readonly=\"readonly\" name=\"items[#index#].drawingNo\"  submitName=\"items[" + i + "].drawingNo\"   value=\"" + obj.drawingNo + "\"  > </td>");
                sb.Append("<td  ><input class=\"textInput required number\" size='9'  name=\"items[#index#].qty\"  submitName=\"items[" + i + "].qty\" value=\"" + obj.qty + "\"  > </td>");
                sb.Append("<td  ><input class=\" textInput  \" size='15'    name=\"items[#index#].typeName\"  submitName=\"items[" + i + "].typeName\" value=\"" + obj.typeName + "\"  > ");
                sb.Append(string.Format(sbProcessingtype.ToString(), i) + " </td>");//调用sbProessingType
                sb.Append("</tr>");
                i++;
            }
            return sb.ToString();
        }

 

转载于:https://www.cnblogs.com/liuwj/p/3421529.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值