I have a ListBox in my webpage (I’m using ASP.NET Web Form 4) and when i want to Convert these ListBox’ Items to String Array it’s not working,
i use this code :
protected void btnSend_Click(object sender, EventArgs e)
{
String[] a= ListBox1.Items.Cast<String>().ToArray();
}
when I click on btnSend and inspect it via Chrome Dev Tools (in the Console tab), I get an error like this:
Unable to cast object of type ‘System.Web.UI.WebControls.ListItem’ to type ‘System.String’
Why is this occurring and how can I fix it?
The
ListBox.Itemscollection contain ListItems.