
{
CheckBox chk = new CheckBox()
chk.Text = "testall" // 这里可以换成数据库的内容
chk.CheckedChanged += new EventHandler(chk_CheckedChanged)
chk.AutoPostBack = true
Page.Form.Controls.Add(chk)
for (int i = 0i <10i++)
{
CheckBox chk2 = new CheckBox()
chk2.Text = "test" + i.ToString() // 这里可以换成数据库的内容
chk2.Checked = (i % 3 == 0)// 这里可以换成数据库的内容
Page.Form.Controls.Add(chk2)
}
}
void chk_CheckedChanged(object sender, EventArgs e)
{
CheckBox all = sender as CheckBox
foreach(Control ctl in Page.Form.Controls)
{
if (ctl is CheckBox)
{
CheckBox chk = ctl as CheckBox
chk.Checked = all.Checked
}
}
}
private LinearLayout.LayoutParams LP_FF = new LinearLayout.LayoutParams (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)ScrollView sv = new ScrollView(this)sv.setLayoutParams( LP_FF )LinearLayout layout = new LinearLayout(this)//线性布局方式 layout.setOrientation( LinearLayout.VERTICAL )//控件对其方式为垂直排列 sv.addView( layout )//把线性布局加入到ScrollView中 setContentView(sv)//设置当前的页面为ScrollView CheckBox tv = new CheckBox(this)tv.setId(10)tv.setText( "fsdfsdfsdfsd" )layout.addView( tv )首先datagridview是绑定数据源的控件,所以不存在想datagridview里面动态添加checkbox一说,可以为checkbox动态赋值,你在拖好datagridview的时候给你面放个checkbox然后 把id赋值,然后再后台获取该checkbox的id,然后根据id获得这个checkbox,在根据数据库给checkboxbox绑定值。。这样就达到你的目的了
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)