您现在的位置: 阿标在线 >> 技术文章 >> .NET技术 >> 数据库应用 >> 正文

在DataGrid中用CheckBox控制

[ 录入:阿标 | 点击数: | 更新时间:2005-3-18 12:51:00]

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




  • 上一篇文章:

  • 下一篇文章: