开发者

How to Assign a Datasource to a Checkboxlist in an ITemplate

开发者 https://www.devze.com 2023-03-01 00:38 出处:网络
I\'m trying to assign a Datasource to a Checkboxlist inside template for my DetailsView control. private class membershipChkLst : 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号