日期:2012-05-23  浏览次数:20369 次


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