asp.net SelectedIndex和SelectedValue的区别
1个回答
展开全部
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Insert(0, "123");//为DropDownList1的第一项添加"123"
DropDownList1.Items.Insert(1, "456");
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex== 0)//选择了第一项
{
Response.Write("" + DropDownList1.SelectedValue.ToString() + "");
}
if (DropDownList1.SelectedValue.ToString() == "456")//选择了名为456的项
{
Response.Write("" + DropDownList1.SelectedValue.ToString() + "");
}
}
一句话说来就是SelectedIndex索引的是项,SelectedValue索引的是变量
{
if (!IsPostBack)
{
DropDownList1.Items.Insert(0, "123");//为DropDownList1的第一项添加"123"
DropDownList1.Items.Insert(1, "456");
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex== 0)//选择了第一项
{
Response.Write("" + DropDownList1.SelectedValue.ToString() + "");
}
if (DropDownList1.SelectedValue.ToString() == "456")//选择了名为456的项
{
Response.Write("" + DropDownList1.SelectedValue.ToString() + "");
}
}
一句话说来就是SelectedIndex索引的是项,SelectedValue索引的是变量
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询