for (int i = 0; i < this.DropDownList1.Items.Count; i++) { if (this.DropDownList1.Items[i].Selected) { Response.Write( this.DropDownList1.Items[i].Text.ToString()); } }
int i = int.Parse(this.ddlSex.SelectValue); switch(i) { case 1: this.ddlSex.SelectItem.Text = '男'; break; case 1: this.ddlSex.SelectItem.Text = '女'; break; default: break;}
<asp:DropDownList ID="ddlProduct" runat="server">
<asp:ListItem Text="产品级数" Value="0"></asp:ListItem>
<asp:ListItem Text="1级" Value="1"></asp:ListItem>
<asp:ListItem Text="2级" Value="2"></asp:ListItem>
<asp:ListItem Text="12级" Value="12"></asp:ListItem>
</asp:DropDownList>
public static string sex=string.Empty;if(this.Dropdownlist.SelectValue=="1")
{
sex="男";
}
else
{
sex="女";
}
<asp:ListItem Value="1">男</asp:ListItem>
<asp:ListItem Value="2">女</asp:ListItem>
</asp:DropDownList>
{
if (this.DropDownList1.Items[i].Selected)
{
Response.Write( this.DropDownList1.Items[i].Text.ToString());
}
}
<option value="1">1</option>
<option value="2">2</option>
</select>
弱弱的问一下,然后呢???
<asp:DropDownList ID="DropDownList3" runat="server">
<asp:ListItem Value="1">男</asp:ListItem>
<asp:ListItem Value="2">女</asp:ListItem>
</asp:DropDownList>
第一种前台直接写
<asp:DropDownList runat="server" ID="ddlGender">
<asp:ListItem Text="--请选择--" Value="0"></asp:ListItem>
<asp:ListItem Text="男" Value="1"></asp:ListItem>
<asp:ListItem Text="女" Value="2"></asp:ListItem>
</asp:DropDownList>
第二种后台cs文件绑定
private void DropDownListBind()
{
ddlGender.Items.Add(new ListItem("--请选择--", "0"));
ddlGender.Items.Add(new ListItem("男", "1"));
ddlGender.Items.Add(new ListItem("男", "1"));
ddlGender.DataBind();
}
两者皆可~
{
ddlGender.Items.Add(new ListItem("--请选择--", "0"));
ddlGender.Items.Add(new ListItem("男", "1"));
ddlGender.Items.Add(new ListItem("女", "2"));
ddlGender.DataBind();
}
修改下第二种打错了~
<asp:asp:DropDownList runat="server" ID="asp:DropDownList1">
<asp:ListItem Text="男" Value="1"></asp:ListItem>
<asp:ListItem Text="女" Value="2"></asp:ListItem>TEXT属性才是页面上显示的
<asp:ListItem Value="1">男</asp:ListItem>
<asp:ListItem Value="2">女</asp:ListItem>
</asp:DropDownList>
this.DropDownList1.SelectedValue//可以取到值了。是1或者2
this.DropDownList1.SelectedItem.Text//就是男或者女了
<asp:DropDownList runat="server" ID="ddlGender">
<asp:ListItem Text="--请选择--" Value="0"></asp:ListItem>
<asp:ListItem Text="男" Value="1"></asp:ListItem>
<asp:ListItem Text="女" Value="2"></asp:ListItem>
</asp:DropDownList>
第二种后台cs文件绑定
private void DropDownListBind()
{
ddlGender.Items.Add(new ListItem("--请选择--", "0"));
ddlGender.Items.Add(new ListItem("男", "1"));
ddlGender.Items.Add(new ListItem("男", "1"));
ddlGender.DataBind();
}
int i = int.Parse(this.ddlSex.SelectValue);
switch(i)
{
case 1:
this.ddlSex.SelectItem.Text = '男';
break;
case 1:
this.ddlSex.SelectItem.Text = '女';
break;
default:
break;}
<asp:ListItem Value="1">男</asp:ListItem>
<asp:ListItem Value="2">女</asp:ListItem>
</asp:DropDownList>
this.DropDownList1.SelectedItem.Value//取值。是1或者2
this.DropDownList1.SelectedItem.Text//取文本,是男或者女了
Text="男";
Text="女";
Label Dro = (Label)e.Item.FindControl("sexLabel");
Dro.Text = (Dro.Text == "1") ? "男" : "女";
<asp:ListItem Value="2">女</asp:ListItem>
<tr>
<td>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="1">男</asp:ListItem>
<asp:ListItem Value="2">女</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
表格式
ID 性别
1 男
2 女
DropDownList.DataValueField = "Id";
DropDownList.DataTextField = "Description";
别的大家都说的很全面了
Text:男
Text:女
就可以了啊