【发布时间】:2016-05-14 09:13:24
【问题描述】:
我在 GridView 中有 3 列。第一列是 CheckBox,第二列是 Label 中的应付金额,第三列是 TextBox to pay Amount。
我的问题是,当复选框被选中时,文本框应该填充第二列值,而当复选框取消选中时,文本框值应该被清除。
请参考我用过的java脚本代码。
<script type="text/javascript">
function SelectChange(ChkId, txt1, total) {
var chk = document.getElementById(ChkId);
UpdateField(ChkId, txt1, total)
}
function UpdateField(ChkId, txt1, total) {
if (document.getElementById(ChkId).checked == true)
{
var lblvalue = document.getElementById(total).value;
document.getElementById(txt1).innerHTML = lblvalue;
}
else
{
document.getElementById(txt1).innerHTML = "0";
}
}
</script>
在后面的代码中...
protected void grdFeesCollection_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txtPayment = (TextBox)e.Row.FindControl("txtPayment");
Label lblDue = (Label)e.Row.FindControl("lblDue");
CheckBox chckSelecthead = (CheckBox)e.Row.FindControl("chckSelect");
chckSelecthead.Attributes["onclick"] = "javascript:return SelectChange('" + chckSelecthead.ClientID + "','" + "','" + txtPayment.ClientID + "','" + lblDue.ClientID + "')";
txtPayment.Attributes["onKeyup"] = "javascript:return UpdateField('" + chckSelecthead.ClientID + "','" + txtPayment.ClientID + "','" + lblDue.ClientID + "')";
}
}
这不是向 TextBox 返回任何值,这就是问题所在。
【问题讨论】:
-
究竟是什么行不通?您收到任何 javascript 错误吗?
-
实际上不起作用。单击复选框时没有得到任何输出
-
试试 chckSelecthead.Attributes["onclick"] = "SelectChange('" + chckSelecthead.ClientID + "','" + "','" + txtPayment.ClientID + "',' " + lblDue.ClientID + "')";如果它不起作用,请发布您收到的 javascript 错误
-
出现错误。未捕获的 ReferenceError:未定义 UpdateField
-
何时单击复选框错误显示 Uncaught ReferenceError: UpdateField is not defined @Cyril
标签: javascript asp.net gridview checkbox