Set CheckBox “Checked” propery in ASP repeater

前端 未结 4 1658
孤独总比滥情好
孤独总比滥情好 2021-01-14 08:16

I was wondering if it\'s possible to set the checked propery of a checkbox, using a bool variable form the repeater\'s datasource?

I\'ve tried several ways but witho

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-14 08:58

    Another solution is handling ItemDataBound event:

    
         
           
        
    
    

    ...

    protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        RepeaterItem ri = e.Item;
        var dataItem = ri.DataItem as YourClassOrInterface;
        var isDefaultCheckBox = ri.FindControl("isDefaultCheckBox") as CheckBox;
        isDefaultCheckBox.Checked = dataItem.IsDefault;
    }
    

提交回复
热议问题