Hi,
Top of the hour to you all. I have got this little problem in asp.net c#. I have got a ListBox which some listItem like
Mango
Orange
Banana
I want to achieve this, when a user clicks on a list item for example click on 'Mango' the mango ListItem should only be disabled in the ListBox ....
Thanks in advance
Loading
Soft CornerPosted Apr 28, 2011, 10:44 AM
listBox1.Items.RemoveAt(listBox1.SelectedIndex);
VulpesPosted Apr 28, 2011, 10:22 AM
On the other hand, when you set Enabled to false for items in the CheckBoxList and RadioButtonList it does gray them out i.e. what you'd normally understand by disabling them.
It may be, of course, that Giwa doesn't mind temporarily removing the items from the ListBox and, if so, then I think your code is the best solution for him.
Soft CornerPosted Apr 28, 2011, 10:14 AM
I think you miss understood some whr, my code will work for Items which are in ListBox control and in MSDN link , they are talking about ListItem for RadioButtonList control or a CheckBoxList control.
and above code i have implemented & it works for me.
Thanks
VulpesPosted Apr 28, 2011, 9:35 AM
Unfortunately, Shrikant's code doesn't work because as it says in the above link:
"You cannot use this property to disable a ListItem control in a DropDownList control or ListBox control."
Soft CornerPosted Apr 28, 2011, 9:11 AM
You Can disable the items in listbox , i took one listbox and a button on page. Button is used to retrive items which are disabled in list.
try this :
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
listBox1.Items.Add("Item1");
listBox1.Items.Add("Item2");
listBox1.Items.Add("Item3");
}
}
protected void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
listBox1.SelectedItem.Enabled = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < listBox1.Items.Count ; i++)
{
listBox1.Items[i].Enabled = true;
}
}
Giwa AbdulhakeemPosted Apr 28, 2011, 9:07 AM
Would really appreciate a snippet on that though.
Cheers
VulpesPosted Apr 28, 2011, 9:03 AM