• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 619
  • Last Modified:

{"Unable to cast object of type 'System.Int32' to type 'System.Web.UI.WebControls.ListItem'."}

I am getting the following error:
{"Unable to cast object of type 'System.Int32' to type 'System.Web.UI.WebControls.ListItem'."}

Code below

foreach (ListItem  item in data)
 {

  }
0
Meinhoonaa
Asked:
Meinhoonaa
1 Solution
 
p_davisCommented:
need more code than that...

what is data? what type is it?
0
 
MeinhoonaaAuthor Commented:
var data = Users.GetUserAccountsAll(UserID);
            foreach (ListItem  item in data)
            {
                lstDealerships.SelectedValue = item.Value;
            }


 public static IQueryable GetUserAccountsAll(int userid)
        {
            ELTDataClasses db = new ELTDataClasses();
            var Data = (from dtuseraccountxref in (db.user_account_xrefs)
                        where dtuseraccountxref.user_id == userid
                        select
                            dtuseraccountxref.account_id
                        );
            return Data.Distinct();

        }
0
 
sameer_goyalCommented:
'data' collection is not compatible with ListItem type

here is something that you can do

var data = Users.GetUserAccountsAll(UserID);
            foreach (var item in data)
            {
               if(item != null)
                lstDealerships.SelectedValue = item.ToString();
            }

Let me know if it works for you
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now