在DataGrid中用CheckBox控制

80酷酷网    80kuku.com

  datagrid|控制
将模板列的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灵活,因为每次都要与服务器通信。



分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: