Hi,
I am trying to get RadGrid to work. What I want to achive is simply a Grid that lets me modify the content of a database table. However, most online samples using the Grid Control is based on ASP.NET - I'm using the Grid Control within a SharePoint WebPart, and therefore needs to do it all programmatically (C# .NET)
When I execute my WebPart, I receive no errors. The Grid simply dosn't render. My code follows below. Any ideas?
- Thanks in advance.
Regards
Jimmy Thomsen
=============================================================================
namespace CompGrid
{
public class Grid : WebPart
{
private ScriptManager sm;
private RadGrid grid;
protected override void OnLoad(EventArgs e)
{
this.EnsureChildControls();
}
protected override void CreateChildControls()
{
if (ScriptManager.GetCurrent(this.Page) != null)
{
this.sm = ScriptManager.GetCurrent(this.Page);
}
else
{
this.sm = new ScriptManager();
this.Controls.Add(this.sm);
}
this.grid = new RadGrid();
this.Controls.Add(this.grid);
this.grid.AllowAutomaticDeletes = true;
this.grid.AllowAutomaticInserts = true;
this.grid.AllowAutomaticUpdates = true;
this.grid.AllowMultiRowEdit = true;
this.grid.AutoGenerateColumns = true;
this.grid.AutoGenerateDeleteColumn = true;
this.grid.AutoGenerateEditColumn = true;
if (this.Page.IsPostBack == false)
{
SqlDataSource dataSource = new SqlDataSource("Data Source=Comp-demo;Initial Catalog=TestDB;User ID=admin;Password=test", "SELECT xaxis, series1, series2 FROM testdata");
dataSource.UpdateCommand = "UPDATE testdata SET xaxis=@xaxis, series1=@series1, series2=@series2 WHERE id=@id";
dataSource.DeleteCommand = "DELETE FROM testdata WHERE id=@id";
dataSource.InsertCommand = "INSERT INTO testdata VALUES (xaxis=@xaxis, series1=@series1, series2=@series2)";
this.grid.DataSourceID = dataSource.ID;
}
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
this.sm.RenderControl(writer);
this.grid.RenderControl(writer);
}
}
}