循环显示出下拉框控件

今天作网站的是遇到个问题,特此记录一下数据库


要实现的效果以下图:ide

212414462.png


下拉框控件的数目是不固定的,是根据某个ID从数据库中读取的,而后要显示在页面上面,而且数据要绑定上去。网站

主要卡住的地方是,如何将控件循环出来,以及将用户选择的内容保存到数据库里面。spa


<asp:Repeater ID="rep" runat="server">3d

   <ItemTemplate>server

       <span class="white1">blog

           <%# Eval("Name") %></span><br />get

               <table width="270" border="0">string

                   <tr>it

                       <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;

       }

相关文章
相关标签/搜索