下拉列表选择问题 [英] dropdownlist select problem

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

问题描述

嗨朋友们,



我遇到下拉列表问题选择



我想选择一个项目来自dropdwonlist,但我也可以选择这个值

-----选择-----



这里一切都很好,但是用户不应该从下拉列表中选择这个---选择----



所以我想避免从下拉列表中选择这个值,



请你能帮助我吗,



谢谢

Hi friends,

am facing problem with dropdownlist Selection

I want to Select a Item from dropdwonlist, but i can select this value also
----- Select -----

everything is fine here, but user shouldnot select this from dropdownlist ---Select ----

so i want to avoid selection this value from dropdownlist ,

please can you help me,

Thanks

推荐答案

嗨Ranjith ,



请试试这个。!



Hi Ranjith,

Please try this.!

// If you want a list of options to be disabled 
foreach ( ListItem item in dropdownlist.Items )
{
    if ( //condition if item's value == 0)
    {
        item.Attributes.Add( "disabled", "disabled" );
        // or
        // item.Enabled = false;
    }
}











or

// Specifically for the 1st option. Throws error when you dont have any options in the dropdownlist. So, becareful with this.
dropdownlist.Items[0].Attributes.Add("disabled", "disabled");





如果不是上述情况,请尝试以下方法。





If not the above, please do try the below one.

item.Enabled = false;





就个人而言,我没有检查过,但应该可以正常工作。如果您有任何问题,请告诉我。我提供了禁用使用属性和启用选项。请自行测试两种选择并使用最适合您应用的选项。



谢谢,

RelicV



Personally, I've not checked it but should work fine. Let me know if you have any issues. I've provided "disable using attributes" and "Enable" options. Please test it for yourself with both options and use the best one that suits your application.

Thank you,
RelicV


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

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