今天作網站的是遇到個問題,特此記錄一下數據庫
要實現的效果以下圖:ide
下拉框控件的數目是不固定的,是根據某個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;
}