zoukankan      html  css  js  c++  java
  • 循环显示出下拉框控件

    今天做网站的是遇到个问题,特此记录一下
    要实现的效果如下图:


    下拉框控件的数目是不固定的,是根据某个ID从数据库中读取的,然后要显示在页面上面,并且数据要绑定上去。
    主要卡住的地方是,如何将控件循环出来,以及将用户选择的内容保存到数据库里面。

    <asp:Repeater ID="rep" runat="server">
    <ItemTemplate>
    <span class="white1">
    <%# Eval("Name") %></span><br />
    <table width="270" border="0">
    <tr>
    <td width="169">
    <%#BlindsOptions(Eval("ID"))%>
    </td>
    <td width="91">
    <img src="../Images/wh.gif" width="14" height="14" alt ="" />
    </td>
    </tr>
    </table>
    </ItemTemplate>
    </asp:Repeater>


    后台

    #region 绑定Repeater控件

    /// <summary>
    /// 绑定Repeater控件
    /// </summary>
    /// <param name="whereStr"></param>
    protected void BindRep(string whereStr)
    {
    whereStr = " ID IN(" + ViewState["BlindsOptionsIds"].ToString() + ")";
    T_BlindsOptionsBLL obj = new T_BlindsOptionsBLL();
    DataSet ds = obj.GetList(whereStr);
    rep.DataSource = ds;
    rep.DataBind();
    }

    #endregion

    #region 循环显示DropDownList控件,并绑定相应的数据

    protected string BlindsOptions(object ID)
    {
    string returnStr = "";
    T_BlindsOptionsItemBLL itemBll = new T_BlindsOptionsItemBLL();
    DataSet ds = itemBll.GetList("OptionID=" + Convert.ToInt32(ID));
    int count = ds.Tables[0].Rows.Count;
    returnStr += "<select name='select_" + ID.ToString() + "' id='select_" + ID.ToString() + "'>";
    if (ds.Tables[0].Rows.Count > 0)
    {
    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
    {
    returnStr += "<option value='" + ds.Tables[0].Rows[i]["ID"] + "' >" + ds.Tables[0].Rows[i]["Name"] + "</option>";
    }
    }
    returnStr += "</select>";
    return returnStr;
    }

    #endregion


    得到下拉框控件的内容,该方法GetBlindsOptions()得到的数据,保存到数据表中的某个字段里面。
    protected string GetBlindsOptions(object objID)
    {
    string strItem="";
    if (objID != null)
    {
    T_CurtainsInfoBLL bll = new T_CurtainsInfoBLL();
    T_CurtainsInfo model = bll.GetModel(Convert.ToInt32(objID));
    string[] boID=model.BlindsOptionsIds.Split(',');
    for (int i = 0; i < boID.Length; i++)
    {
    strItem += Request["select_" + boID[i] + ""] + ",";
    }
    }
    string returnStr = strItem.Substring(0, strItem.Length - 1);
    return returnStr;
    }

  • 相关阅读:
    windows8.1专业中文版一个可用的密钥分享
    ARTS打卡计划第四周-TIPS-自定义一个LikeFilter
    ARTS打卡计划第四周-ALGORITHM
    ARTS打卡计划第三周-Share-spring,echart开发统计图的经验
    ARTS打卡计划第三周-Tips
    ARTS打卡计划第三周-Algorithm
    ARTS打卡计划第三周-Review
    ARTS打卡计划第二周-Share-使用java注解对方法计时
    ARTS打卡计划第二周-Tips-mysql-binlog-connector-java的使用
    ARTS打卡计划第二周-Review
  • 原文地址:https://www.cnblogs.com/ahao214/p/3482897.html
Copyright © 2011-2022 走看看