日期:2014-05-20  浏览次数:20480 次

GridView中有两个模板列,一个checkbox列,一个TextBox列,如何用js控制,在checkbox列选择时才可以输入文本?
GridView中有两个模板列,一个checkbox列,一个TextBox列,如何用js控制,在checkbox列选择时才可以输入文本?
当checkbox列没选择时,将文本中的内容清空。

------解决方案--------------------
checkbox列 <itemtemplate> <input type= 'CheckBox " onclick= "GoChangeTextBox(this); "> </itemtemplate>


function GoChangeTextBox(obj) { var txt = obj.parentElement.nextSibling.firstChild; txt.disabled = !obj.checked; if(!obj.checked) txt.value = " "; }
------解决方案--------------------
模板列
在checkbox的onchange事件中:

GridViewRow editRow = (GridViewRow)(((Control)sender).Parent.Parent);
TextBox txtMaster = (TextBox)(editRow.FindControl( "txtMaster "));
txtMaster.Enabled = !(txtMaster.Enabled);