控件不同的类似方法如何合成一个

 逐行绑定RadioButtonList和逐行绑定CheckBoxList,除了控件类型和控件名外,其他都一样。不想把相同的方法写两遍,怎么办?

补充:因为有RadioButtonList rbl = (RadioButtonList)e.Item.FindControl(controlname);而范型不能convert,所以范型使用失败。


蓝山帝景
浏览 417回答 2
2回答

绝地无双

ListControl list = (ListControl)e.Item.FindControl("controlname");list.DataSource=  xxx;list.DataBind();或者list.Items.Add(...);RadioButtonList和CheckBoxList都属于ListControl

慕桂英546537

构造Binding  new Binding(   string propertyName,   object dataSource,   string dataMember);比如:Binding bd = new Binding("Text",数据源对象,"数据源成员");TextBox.DataBindings.Add(bd );Binding bd = new Binding("Checked",数据源对象,"数据源成员");CheckBoxList.DataBindings.Add(bd );
打开App,查看更多内容
随时随地看视频慕课网APP