简单的SELECT取值问题
我想读取数据库中的下拉框默认值。。
我定义了一个public string KouWei;
<SELECT id= "KouWeiSelect " name= "KouWeiSelect " runat= "server ">
<OPTION value= " "> 请选择 </OPTION>
<OPTION value= "0 " <%# KouWei.ToString() == "0 " ? "selected ": " "%> > 差(0) </OPTION>
<OPTION value= "1 " <%# KouWei.ToString() == "1 " ? "selected ": " "%> > 一般(1) </OPTION>
<OPTION value= "2 " <%# KouWei.ToString() == "2 " ? "selected ": " "%> > 好(2) </OPTION>
<OPTION value= "3 " <%# KouWei.ToString() == "3 " ? "selected ": " "%> > 很好(3) </OPTION>
<OPTION value= "4 " <%# KouWei.ToString() == "4 " ? "selected ": " "%> > 非常好(4) </OPTION>
</SELECT>
但提示““HtmlSelect”不能有类型为“DataBoundLiteralControl”的子级。 ”
正确写法应该怎么样的。
不想用KouWeiSelect.Items.Insert的方式。
------解决方案--------------------在后台绑定,和用dropdownlist一下.
------解决方案--------------------改成:
<SELECT id= "KouWeiSelect " name= "KouWeiSelect " runat= "server ">
<OPTION value= " "> 请选择 </OPTION>
<OPTION value= "0 "> 差(0) </OPTION>
<OPTION value= "1 "> 一般(1) </OPTION>
<OPTION value= "2 "> 好(2) </OPTION>
<OPTION value= "3 "> 很好(3) </OPTION>
<OPTION value= "4 "> 非常好(4) </OPTION>
</SELECT>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 0; i < this.KouWeiSelect.Items.Count; i++)
{
if (this.KouWeiSelect.Items[i].Value == KouWei)
{
this.KouWeiSelect.Items[i].Selected = true;
}
}
}
}