开发者

asp.net C# SelectedItem.Selected=false Object refrence not set to an object

开发者 https://www.devze.com 2023-02-22 10:06 出处:网络
downlist.SelectedItem.Selected=false; if the downlist\'s SelectedItem is null,开发者_Python百科after running this code,there will be a error what \"Object refrence not set to an object\";
downlist.SelectedItem.Selected=false;

if the downlist's SelectedItem is null,开发者_Python百科after running this code,there will be a error what "Object refrence not set to an object"; how can i modify the code to this

downlist.ClearSelection();

afert modifying,can i avoid above-mentioned exception


Well, how about the following?

if (downlist.SelectedItem != null) 
{
    downlist.SelectedItem.Selected=false;
}

Im sure that if I fully understood your problem then there would be a more sophisticated solution, but this should do the trick (unless multiple threads access downlist.SelectedItem, which they shouldn't in a typical ASP.Net application).

0

精彩评论

暂无评论...
验证码 换一张
取 消