I have this C# code.
j = myAccountDataset.Tables["AccountsTables"].Rows.Count;
for (i = 0; i <= (j - 1); i++ )
{
listAccountList.Items.Add(myAccountDataset.Tables[0].Rows[i][1]);
}
this.listAccountList.SelectedIndex = 0;
the idea is to iterate inside the dataset and add the items to the list.
but i am getting the following errors:
Error 1 The best overloaded method match for ‘System.Web.UI.WebControls.ListItemCollection.Add(string)’ has some invalid arguments
Argument1: cannot convert from ‘object’ to ‘string’
i must be doing something wrong. thye error is in the line: listAccountList.Items.Add(myAccountDataset.Tables[0].Rows[i][1]);
thank you.
The ListItemCollection’s Add method only accepts two types – a string or a ListItem
See the MSDN documentation here. You need to pass a string instead of an object: