Click here to Skip to main content
16,015,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to bind combobox in silverlight using WCF. i have tried below code but comobobox doesn't display any values??.. code as follows..
     public class Appsrvvice : IAppsrvvice
     {
       
        public void DoWork()
        {
         }

        public List<fillupcombox> fillup()
        {
            List<string> x=new List<string>();
            List<string> y=new List<string>();

            string connectionstring = "server=localhost;User Id=root;password=root;Persist Security Info=True;database=mv_store";
            string msg;

             msg = "";
            MySqlConnection con = new MySqlConnection(connectionstring);
            MySqlDataAdapter ad = new MySqlDataAdapter("select Product_Name,Product_Id from product_detail Order by Product_Name", con);

            DataTable dt = new DataTable();

            try
            {
                ad.Fill(dt);
              //  return dt;

                for(int i=0;i<dt.Rows.Count;i++)
                {
                    x.Add(dt.Rows[i]["Product_Name"].ToString());
                    y.Add(dt.Rows[i]["Product_Id"].ToString());
                }

            }

            catch (Exception e)
            {

                msg = e.Message;
                return null;

            }
            finally
            {
                ad.Dispose();
            }


            return new List<fillupcombox>()
            {
                new fillupcombox()
                {
                    Texts=x,
                    Valuess=y
                }
            };
        }
    }



    [ServiceContract]
    public interface IAppsrvvice
    {

        [OperationContract]
        void DoWork();

        [OperationContract]
        List<fillupcombox> fillup();

    }

    [DataContract]
    public class fillupcombox
    {

        [DataMember]
        public List<string> Texts
        {
            get;
            set;
        }

        [DataMember]
        public List<string> Valuess
        {
            get;
            set;

        }

    }

Heres My main page code

     public MainPage()
       
     {
            InitializeComponent();

            ServiceReference1.AppsrvviceClient obj = new ServiceReference1.AppsrvviceClient();
            obj.fillupCompleted += new EventHandler<ServiceReference1.fillupCompletedEventArgs>(fillupCompletedp);
            obj.fillupAsync();
            
           

        }


        public void fillupCompletedp(object sender, ServiceReference1.fillupCompletedEventArgs e)
        {
            

             comboBox1.ItemsSource =e.Result;
          

        }



No Values is populated in the combobox. Any idea where i am wrong?
Posted

1 solution

Hi
In the above code fillupcombo ( WCF DataContract) it is userdefined datatype which contains two List of String , so in silverlight app you need to mention which one you need to bind the data to the ComboBox.Just make the change in silverlight fillupCompleted event compelted as follows then it will work

System.Collections.ObjectModel.ObservableCollection <ServiceReference1.fillupcombox> mylist = e.Result;

cmbxList.ItemsSource = mylist[0].Texts;



Regards
Siraz
 
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