当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > DataGrid模板列应用:在DataGrid中用CheckBox控制TextBox的Enabled属性

ASP.NET
HTML服务器控件介绍:HtmlInputFile控件
HTML服务器控件介绍:HtmlInputHidden控件
HTML服务器控件介绍:HtmlInputImage控件
HTML服务器控件介绍:HtmlInputRadioButton控件
HTML服务器控件介绍:HtmlInputText控件
HTML服务器控件介绍:HtmlSelect控件
HTML服务器控件介绍:HtmlTable控件
HTML服务器控件介绍:HtmlTableCell控件
HTML服务器控件介绍:HtmlTableRow控件
HTML服务器控件介绍:HtmlTextArea控件
Web服务器控件:AdRotator控件
Web服务器控件:Button控件
Web服务器控件:Calendar控件
Web服务器控件:CheckBox控件
Web服务器控件:CheckBoxList控件
Web服务器控件:DropDownList控件
Web服务器控件:HyperLink控件
Web服务器控件:Image控件
Web服务器控件:ImageButton控件
Web服务器控件:Label控件

ASP.NET 中的 DataGrid模板列应用:在DataGrid中用CheckBox控制TextBox的Enabled属性


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 156 ::
收藏到网摘: n/a

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