Tag Archives: visual studio

Binding SPList to Binding Controls.

To bind a SPList to a binding control list for example the DetailsView data control you will need to provide a DataSource to it. The problem is SPList doesn’t implment the IDataSource interface, but I have discovered that there is a SPDataSource which allows you to pass a SPList object as a parameter in the constructor. Below is a code

var spList = SPContext.Current.Web.Lists["List Name"];
var ds = new SPDataSource(spList);
DetailsView1.DataSource = ds;
DetailsView1.DataBind();

Deploying Assembly Files With Your Sharepoint Solution

Recently I have been working on a Sharepoint 2010  and I had created a Class Library project that will contain some classes and methods. One of the custom webparts I had created was calling a method from one of the class, but when I press F5 to deploy and test my web part I got an error and my assembly file was missing in Sharepoint. I realised that my Class Library assembly file was not deployed. 

Below is a simple step by step instruction on how to include a assembly file in your Sharepoint package.

For example here I have a solution with a Sharepoint 2010 and a class library project. In the Sharepoint 2010 project there is a package folder containing a file called Package.package

visual studio 2010 solution

Continue reading

How to access a common property from multiple form controls.

Recently I had someone posting a question about how to access the Text properties of a different control. I thought of using reflection, because you don’t need to know the type of control you are handling and you don’t need to type cast the object.

If you are handling one specific control, there is no point using reflection, I would suggest just type cast it.

Below is a code snippet from an example I have written to demonstrate how to share one event method with multiple controls on a form. In the method it will get the string value from the Text property of the selected control.

Source Code: ReflectionExample1.zip

<span style="color: blue">using </span>System;
<span style="color: blue">using </span>System.Collections.Generic;
<span style="color: blue">using </span>System.ComponentModel;
<span style="color: blue">using </span>System.Data;
<span style="color: blue">using </span>System.Drawing;
<span style="color: blue">using </span>System.Linq;
<span style="color: blue">using </span>System.Text;
<span style="color: blue">using </span>System.Windows.Forms;
<span style="color: blue">using </span>System.Reflection;

<span style="color: blue">namespace </span>ReflectionExample1
{
    <span style="color: blue">public partial class </span><span style="color: #2b91af">Form1 </span>: <span style="color: #2b91af">Form
    </span>{
        <span style="color: blue">public </span>Form1()
        {
            InitializeComponent();
        }

        <span style="color: blue">private void </span>DisplayText(<span style="color: blue">object </span>sender, <span style="color: #2b91af">MouseEventArgs </span>e)
        {
            <span style="color: #2b91af">Type </span>type = sender.GetType();
            <span style="color: #2b91af">PropertyInfo </span>pInfo = type.GetProperty(<span style="color: #a31515">"Text"</span>);
            <span style="color: #2b91af">String </span>value = pInfo.GetValue(sender, <span style="color: blue">null</span>).ToString();
            <span style="color: #2b91af">MessageBox</span>.Show(value);
        }
    }
}