How to identify the ListBox is selected or not.

Posted by Vanchi050585 under ASP.NET on 7/13/2010 | Views : 2049 | Status : [Member] | Replies : 2
hi all,

How to identify the ListBox is selected or not.

Thanks in Advance,
vanchi

Thanks
tvn



Responses

Posted by: Raja on: 7/13/2010 [Member] Starter

Up
0
Down
There are many ways:

1. listbox.SelectedIndex = < 0 then not selected
2. listbox.SelectedValue = null then not selected

Try to printout the value of SelectedIndex and SelectedValue when you have not selected the listbox and you will get them how to know if listbox is selected or not :)

Thank you.

Regards,
Raja, USA

Vanchi050585, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeks on: 7/21/2010 [Member] Bronze

Up
0
Down
Hi,
If you are using the VS2008 please try below code.

create static function in static class

public static class Extensions

{
public static bool IsSelected(this ListBox lst)
{
return lst.SelectedValue != null ? (lst.SelectedValue > 0) : false;
}
}


Calling this function.

if(lst.IsSelected())

{
MessageBox.Show("ListBOx is Selected");
}



Vanchi050585, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response