Hi,
We've recently installed Sharepoint Services on our network and are in the process of migrating our current intranet over to the new service. All very nice so far.
But - I've been trying to write my own Web Parts to plug into SS. I'm new to .NET so it's becoming an arduous task... but I'm making progress slowly.
So far, I have a web part that pulls a telephone list out of a SQL server database and displays it in a datagrid. Unfortunately, none of the sorting functionality works... I've been trying different tutorials for the past couple of days and getting no-where.
Does anyone have a decent beginners step by step in plain english tutorial to recommend?
Or, could someone look at my code and tell me where I'm going wrong?
Thanks in advance,
Craig.
We've recently installed Sharepoint Services on our network and are in the process of migrating our current intranet over to the new service. All very nice so far.
But - I've been trying to write my own Web Parts to plug into SS. I'm new to .NET so it's becoming an arduous task... but I'm making progress slowly.
So far, I have a web part that pulls a telephone list out of a SQL server database and displays it in a datagrid. Unfortunately, none of the sorting functionality works... I've been trying different tutorials for the past couple of days and getting no-where.
Does anyone have a decent beginners step by step in plain english tutorial to recommend?
Or, could someone look at my code and tell me where I'm going wrong?
Thanks in advance,
Craig.
Code:
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Data;
namespace Web_Part1
{
[Guid("857de561-535a-4292-ada2-dffddce902da")]
public class Web_Part1 : System.Web.UI.WebControls.WebParts.WebPart
{
public Web_Part1()
{
this.ExportMode = WebPartExportMode.All;
}
protected override void Render(HtmlTextWriter writer)
{
// TODO: add custom rendering code here.
try
{
String sqlConnection = "Data Source=xx;Initial Catalog=xx;User ID=xx;Password=xx";
String sqlString = "Select * from tblTelephoneList";
System.Data.SqlClient.SqlConnection mySQLConnect =
new System.Data.SqlClient.SqlConnection(sqlConnection);
mySQLConnect.Open();
System.Data.SqlClient.SqlCommand myCmd = new System.Data.SqlClient.SqlCommand(sqlString, mySQLConnect);
System.Data.SqlClient.SqlDataAdapter myAdapter = new System.Data.SqlClient.SqlDataAdapter(myCmd);
DataSet ds = new DataSet();
myAdapter.Fill(ds, "Data");
System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();
dg.DataSource = ds.Tables[0];
dg.DataBind();
dg.RenderControl(writer);
}
catch (Exception except)
{
writer.Write("Funnily enough, there's a database error.. Who'd have thought... ;)");
writer.Write("<br />" + except);
}
}
}
}