How to Assign a Datasource to a Checkboxlist in an ITemplate
I'm trying to assign a Datasource to a Checkboxlist inside template for my DetailsView control.
private class membershipChkLst : ITemplate
{
private CheckBoxList chk_lst_Members;
public membershipChkLst()
{
chk_lst_Members = new CheckBoxList();
}
public object AssignDataSource
{
get { return this.chk_lst_Members.DataSource; }
set { this.chk_lst_Members.DataSource = value; }
}
public void InstantiateIn(Control container)
{
if (container != null)
{
开发者_如何学Go container.Controls.Add(chk_lst_Members);
}
}
}
Is the syntax correct or am I doing it wrong?
Something like this
public membershipChkLst(DataTable dt)
{
chklst = new CheckBoxList();
chklst.ID = "chklstid";
chklst.DataSource = dt;
chklst.DataBind();
}
Pass in your required datasource (i added DataTable just to show) and this would help achieve what you want.
精彩评论