Wednesday, February 10, 2010

Adding Silverlight application(.xap file) in sharepoint web part.

Import the System.Web.UI.SilverlightControls to use the silverlight control.

Create the object of Silverlight control and specify the path of .xap file. Add this control in web part.

Silverlight silverlightControl = new Silverlight();
silverlightControl.ID = "DemoId";
silverlightControl.Source = "~/_layouts/1033/Demo.xap";
silverlightControl.Width = Unit.Percentage(100);
silverlightControl.Height = new Unit(400);
silverlightControl.AutoUpgrade = true;

this.Controls.Add(silverlightControl);

Monday, February 8, 2010

Bind dropdown list with sharepoint choice column as data source programmatically

Easy way to populate the dropdown list with databind option instead of looping the items in list for Choice column.

private void FillDropDownList(SPList list , DropDownList drpList , string columnName)
{
try
{
SPFieldChoice field = (SPFieldChoice)list.Fields[columnName];
drpList.DataSource = field.Choices;
drpList.DataBind();
}
catch (Exception ex)
{}
}