下拉列表的selectedindex [英] selectedindex of a Dropdownlist

查看:101
本文介绍了下拉列表的selectedindex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (DropDownList1.SelectedIndex >= 0 )
       {
           Literal2.Text  = DropDownList1.SelectedIndex .ToString ();
       }


我无法在if循环内的文字中显示选定的索引值,在上面的代码中,其将选定的索引值显示为0,任何替代方法都建议我.


i am not able to show a selected index value in a literal within the if loop, in the above code its showing the selected index value as 0, any alternative please suggest me.

推荐答案

尝试一下

try this

if (DropDownList1.SelectedIndex != 0 )
       {
           Literal2.Text  = DropDownList1.SelectedIndex .ToString ();
       }


您的代码是正确的,只需将其写入索引更改或将dropdownlist的AutopostBack属性设置为True.

Your code is correct just write it into index change or set AutopostBack property of dropdownlist to True.

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex >= 0)
            lbl.Text = DropDownList1.SelectedIndex.ToString();
    }


这篇关于下拉列表的selectedindex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆