本文介绍了GET ERROR无法修改Controls集合,因为控件包含代码块(即)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Quote:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
我在MasterPage上设置gridview并使用JAVASCRIPT我想做的任务,当我点击gridview的行值存储时隐藏的标志和我想做的事情。 但问题是我调试时发现错误
I set the gridview on MasterPage and using JAVASCRIPT i want to do the task in which , when i click on the Row of gridview the value store into hidden flag and to what i want to do. but the problem is when i debug the error is found
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).i写这段代码// 来自javascript ...
i writing this code// from javascript...
var curSelRowIndex = -1; var curSelRow = null; function GridDblClick(varRowIndex) { debugger; if (curSelRow != null) { curSelRow.style.backgroundColor = (curSelRowIndex % 2 == 0 ? "#EBEBEB" : "activeborder"); } document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].style.backgroundColor = '#ffc0cb'; curSelRow = document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex]; curSelRowIndex = varRowIndex; document.getElementById('<%=hidMID.ClientID %>').value = 'E~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[1]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[2]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[3]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[4]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[5]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[6]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[7]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[8]); }代码背后.cs
on code behind .cs
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowIndex > -1) { e.Row.Attributes.Add("ondblclick", "javascript:return GridDblClick(" + (e.Row.RowIndex + 1) + ")"); } }主要的事情是我使用这个代码并在MASTERPAGE上放置这个GRIDVIEW .. PLZ建议我为此做什么>>>
推荐答案一个解决方案可以尝试在正文部分html编写你的javascript代码 one solution could try writing your javascript code in the body section html
将代码块替换为<%#而不是<%= 参考 aspnet-controls-collection-can-not [ ^ ] 所述的控件收集-不能待改性因为-的控制-contains-code-block [ ^ ] Replace the code block with <%# instead of <%= Refer aspnet-controls-collection-cannot-be[^] the-controls-collection-cannot-be-modified-because-the-control-contains-code-block[^]
更多推荐
GET ERROR无法修改Controls集合,因为控件包含代码块(即)。
发布评论