逐行綁定RadioButtonList和逐行綁定CheckBoxList,除了控件類型和控件名外,其他都一樣。不想把相同的方法寫兩遍,怎么辦?補充:因為有RadioButtonList rbl = (RadioButtonList)e.Item.FindControl(controlname);而范型不能convert,所以范型使用失敗。
2 回答

絕地無雙
TA貢獻1946條經驗 獲得超4個贊
ListControl list = (ListControl)e.Item.FindControl("controlname");
list.DataSource= xxx;
list.DataBind();
或者
list.Items.Add(...);
RadioButtonList和CheckBoxList都屬于ListControl

慕桂英546537
TA貢獻1848條經驗 獲得超10個贊
構造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 );
- 2 回答
- 0 關注
- 447 瀏覽
添加回答
舉報
0/150
提交
取消