Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to bind IEnumerable object to combobox datasource? or How to convert IENumerable object to datatable ot dataset?

C#
IEnumerable<alist> objList = objservice.GetList(1,combobox1.SelectedValue.ToString(), "A", 72, 523 , null);

if (dsDetails == null || dsDetails.Tables[0].Rows.Count == 0)
            {
               DataRow drDetails = dsDetails.Tables[0].NewRow();
                drDetails["BName"] = "No Records";
                drDetails["BCode"] = 0;
                drDetails.Tables[0].Rows.InsertAt(drDetails , 0);
            }
            else if (dsDetails.Tables[0].Rows.Count > 1)
            {
               DataRow drDetails = dsDetails.Tables[0].NewRow();

                drDetails["BName"] = "<-- Select -->";
                drDetails["Code"] = 0;
                dsDetails.Tables[0].Rows.InsertAt(drDetails, 0);

            }
            //cb1.DisplayMember = "BName";
            //cb1.ValueMember = "BCode";
            //cb1.DataSource = dsDetails.Tables[0];


            cb1.DisplayMember = "Description";
            cb1.ValueMember = "ACode";  
            cb1.DataSource = objApproverlist;



I want to use objApproverlist instead of dsGetails to cb1.datasource
Posted
Updated 26-Aug-15 0:34am
v3
Comments
Sathish km 26-Aug-15 7:05am    
hw Can i achieve this? where to put?

1 solution

You can't bind an IEnumerable to a datasource, but there are many object that can. Most are far simpler than a DataTable.

What about a List:

C#
//You don't need this method.  Just a demo of ToList()
public List<t> ToList(this IEnumerable<t> source){
   return source.ToList();
}

</t></t>


Hope that helps ^_^
Andy
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900