Hello,
You can take advantage of using
CMS.GlobalHelper.RequstStockHelper class that provides two methods
Add /
GetItem. The
Add method allows you to insert a reference to some object into
HttpContext.Current.Items collection whereas
GetItem can be used to retrieve the object reference.
So, you can modify the
SQLDataSource web part (
~\CMSWebParts\DataSources\SQLDataSource.ascx.cs) and implement the
OnInit method in which you can add a reference to the
SQLDataSource control to
HttpContext.Current.Items collection:
protected override void OnInit(EventArgs e)
{
CMS.GlobalHelper.RequestStockHelper.Add("SqlDataSource", this.srcSQL);
base.OnInit(e);
}
the
srcSQL is the ID of the
SqlDataSource control used in
SqlDataSource web part.
Now, you should be able to get this
SqlDataSource control and its
DataSource in your custom web part:
protected void Page_Load(object sender, EventArgs e)
{
if (CMS.GlobalHelper.RequestStockHelper.Contains("SqlDataSource"))
{
object o = CMS.GlobalHelper.RequestStockHelper.GetItem("SqlDataSource");
CMS.Controls.SQLDataSource sqlDataSource = o as CMS.Controls.SQLDataSource;
if (sqlDataSource != null)
{
DataSet dataSource = sqlDataSource.DataSource as DataSet;
if (!DataHelper.DataSourceIsEmpty(dataSource))
{
// custom code
}
}
}
}
Best regards,
Michal Legen