Search This Blog


Oct 19, 2010

Tutorial: How to fill Drop down List in Silver Light

Sponsored Links:
In Silverlight we can not directly talk with the ADO.Net. We will use WCF for this purpose.
We can fill the DropDown List in few steps.

1. Create the object of WCF

ServiceReference1.ServiceClient objService;
// In above line "ServiceReference1" is the name of WCF

/*Create a method LoadData */

public void LoadData(){ // Assign Memory to the object of web service
objService = newServiceReference1.ServiceClient();

// Handler
objService.GetValueCompleted +=
  // Call Web Service method which return the complete data

// Handler Definition
void objService_GetValueCompleted
object sender, ServiceReference1.GetAssetCompletedEventArgs e
// Object of Observable collection which holds the contract class 
ObservableCollection<test.ServiceReference1.MyWContracts> obj= e.Result;
// in e.result returns the complete data
// Here GetSubTypes is My Class
List<GetSubTypes> details = new List<GetSubTypes>();
if (e.Result.Count > 0)
foreach (test.ServiceReference1.MyContracts graph in obj)
// Add all items to Combo/Graph
4. Class
 public class GetSubTypes
public string _sSubTypes { get; set; }
public GetSubTypes(string subtypes)
this._sSubTypes = subtypes;
5. Finally call the LoadData Method, you can call your method inside the 
Constructor of your class as


Follow by Email