动态生成dropdownlist

                    <td colspan="4" id="td_ddl" runat="server"> 
                    </td>
后台代码:

            #region 动态拼出未知个数的下拉框列表,每个分别绑定成组的三级指标
            if (dt != null && dt.Rows.Count > 0)
            {
                string tempIndi = "";
                int count = 0;
                //循环拼出由各条指标的评价标准组成的下拉框html,默认认为同一条二级指标下的三级指标绑定为一个下拉框,否则为不同的二级指标创建下一个下拉框
               for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (tempIndi != dt.Rows[i]["ST_LEVEL2_PLAN_TITLE"].ToString().Trim())
                    {
                        if (tempIndi.Length == 0)
                        {
                            td_ddl.InnerHtml = "<table  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\" width:100%;\"><tr><td>";
                        }
                        else
                        {
                            td_ddl.InnerHtml = "</asp:DropDownList>";
                        }
                        td_ddl.InnerHtml += "<asp:DropDownList runat=\"server\" ID=\"ddl" + count + dt.Rows[i]["IN_LEVEL3_PLAN_ID"].ToString().Trim() + "\" AutoPostBack=\"true\" >";
                        td_ddl.InnerHtml += "<asp:ListItem Value=\"" + dt.Rows[i]["IN_LEVEL3_PLAN_ID"].ToString().Trim() + "\">" + dt.Rows[i]["ST_LEVEL3_PLAN_TITLE"].ToString().Trim() + "</asp:ListItem>";
                        tempIndi = dt.Rows[i]["ST_LEVEL2_PLAN_TITLE"].ToString().Trim();
                        count++;
                    }
                    else
                    {
                        td_ddl.InnerHtml += "<asp:ListItem Value=\"" + dt.Rows[i]["DE_LEVEL3_PLAN_SCORE"].ToString().Trim() + "\">" + dt.Rows[i]["ST_LEVEL3_PLAN_TITLE"].ToString().Trim() + "</asp:ListItem>";
                    }
                }
                td_ddl.InnerHtml = "</asp:DropDownList>";
                hidDdlCount.Value = count.ToString();
            #endregion

            //循环查找出之前动态生成的dropdownlist
            for (int j = 0; j < int.Parse(hidDdlCount.Value); j++)
            {
                DropDownList ddl1 = (DropDownList)(td_ddl.FindControl("ddl" + j + dt2.Rows[0]["ST_DAILY_ID"].ToString()));
                if (ddl1 != null)
                {
                    ddl1.SelectedIndex = ddl1.Items.IndexOf(ddl1.Items.FindByValue(dt2.Rows[0]["ST_DAILY_ID"].ToString()));
                    break;
                }

                DropDownList ddl2 = (DropDownList)(td_ddl.FindControl("ddl" + j + dt2.Rows[0]["ST_WORDNUM_ID"].ToString()));
                if (ddl2 != null)
                {
                    ddl2.SelectedIndex = ddl2.Items.IndexOf(ddl2.Items.FindByValue(dt2.Rows[0]["ST_WORDNUM_ID"].ToString()));
                    break;
                }
            } 

        }

 

转载于:https://www.cnblogs.com/neru/p/3620528.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值