在DataGrid中用CheckBox控制-.NET教程,数据库应用
来源:作者: 发布时间:2007-12-26 02:04:54

将模板列的checkbox的autopostback属性配置为true,因为在模板列中的控件没有事件,故在aspx页面写事件程式,同时将checkbox的oncheckedchanged事件配置为所需要的事件程式。示例如下:
void check_change(object sender, eventargs e)
{
textbox txtdescription;
foreach(datagriditem item in itemsgrid.items)
{
selection = (checkbox)item.findcontrol("chkenabled");
txtdescription = (textbox)item.findcontrol("txtdescription");
if (selection.checked) { txtdescription.enabled=false; }
else { txtdescription.enabled=true;}
}
}
这样,当选中checkbox时,textbox中的内容将不可编辑,这个例子的缺陷在于没有使用就javascript灵活,因为每次都要和服务器通信。
|
还没有关于此文章的相关评论!