My user control has several components, but the main is a CheckBoxList, I want to load it with a SqlDataSource, from the page, allowing me to use multiple instances of my control with different sources.
My first attempt was to expose the checkboxlist's DataSourceID in my user control:
public String DataSourceID
{
get { return myCheckList.DataSourceID; }
set { myCheckList.DataSourceID = value; }
}
And set it from my aspx, just like I would do for any other control:
<asp:SqlDataSource ID="sdsTest" .... ></asp:SqlDataSource>
<uc1:MyControl ID="controlTest" runat="server" DataSourceID="sdsTest" .. />
Didn't work!... So, found in internet (and tried) the following..
public String DataSourceID { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if ((this.DataSourceID ?? "") != "")
{
SqlDataSource datasource = Utils.FindControl(Page, this.DataSourceID) as SqlDataSource;
if (datasource != null)
{
myCheckList.DataSource = datasource;
myCheckList.DataBind();
}
}
}
Even when the SqlDataSource is found, and the DataBind() is executed, my checkbox list is still not loaded. Am I missing something obvious?
Thanks in advance!