ASP面板内部扩展的GridView [英] Expandable Gridview inside ASP Panel
问题描述
我要添加一个ASP面板内的可扩展ASP格,我想通过改变面板的可见真/假选项,以使有形/无形。
如果我删除的asp:面板ID =测试1,该网站与exandable gridview的工作没有问题打开
一旦我添加code中的面板内我得到一个错误信息:
防爆pression预期。
源错误:
线46:其中; A HREF =JavaScript的:divexpandcollapse('的div&下;%#评估和演示(安培; QUOT; reporting_group&放大器; QUOT)%GT;');>
有没有人能解释为什么发生这种情况以及如何避免它。我也曾尝试阿贾克斯TabContainer的具有相同的结果。
见下文code。
< SCRIPT LANGUAGE =JavaScript的类型=文/ JavaScript的>
功能divexpandcollapse(divname){
VAR的div =的document.getElementById(divname);
VAR IMG =的document.getElementById('IMG'+ divname);
如果(div.style.display ==无){
div.style.display =块; img.src =图像/图标/ minus.jpg
}其他{div.style.display =无; img.src =图像/图标/ plus.jpg }
}< / SCRIPT>< ASP:面板ID =测试1=服务器>
面板1 LT; BR />
< ASP:的UpdatePanel ID =UP_TabContainer=服务器的UpdateMode =条件>
<&的ContentTemplate GT;
< ASP:GridView控件ID =GV_SL=服务器的AutoGenerateColumns =FALSE
的DataSourceID =SQL_WeeklyOnRowCommand =GV_SL_RowCommand
OnRowDataBound =gvUserInfo_RowDataBound>
<柱体和GT;
< ASP:的TemplateField ItemStyle-WIDTH =50像素>
<&ItemTemplate中GT;
< A HREF =JavaScript的:divexpandcollapse('DIV<%#评估和演示(安培; QUOT; reporting_group&安培; QUOT;)%GT;');>
< IMG ID =imgdiv<%#的eval(reporting_group)%>中WIDTH =15px的边界=0SRC =图像/图标/ plus.jpg/>
&所述; / A>
< / ItemTemplate中>< ItemStyle宽度=40像素/>
< / ASP:的TemplateField>
< ASP:BoundField的数据字段=名称的HeaderText =集团SORTEX pression =名/>
< ASP:BoundField的数据字段=ASL的HeaderText =SL%法只读=真/>
< ASP:的TemplateField>
<&ItemTemplate中GT;
&所述; TR>
&所述; TD>
< DIV ID ='DIV<%#的eval(reporting_group)%>'风格=显示:无;位置:亲属;
左:15px的;溢出:汽车>
< ASP:GridView控件ID =gvChildGrid=服务器的AutoGenerateColumns =false的>
<柱体和GT;
< ASP:BoundField的数据字段=公制
的HeaderText =/>
< ASP:BoundField的数据字段=实际的HeaderText =实际/>
< /专栏>
< / ASP:GridView的>
< / DIV>
< / TD>
< / TR>
< / ItemTemplate中>
< / ASP:的TemplateField>
< /专栏>
< / ASP:GridView的>
< BR />
< ASP:SqlDataSource的ID =SQL_Weekly=服务器
的ConnectionString =下;%$的ConnectionStrings:的ConnectionString%>中的SelectCommand =SQL查询< SelectParameters>
< / SelectParameters>
< / ASP:SqlDataSource的>
< ASP:SqlDataSource的ID =SQL_Group=服务器
的ConnectionString =下;%$的ConnectionStrings:的ConnectionString%>中的SelectCommand =SQL查询>< / ASP:SqlDataSource的>
< /&的ContentTemplate GT;
<&触发器GT;
< ASP:AsyncPostBackTrigger控件ID =DateSelection
事件名称=的SelectedIndexChanged/>
< /触发器>
< / ASP:的UpdatePanel>
< BR />
< / ASP:面板>
试着改变你的链接触发JavaScript来像这样的方式:
< A HREF =#的onclick =divexpandcollapse('DIV<%#的eval(reporting_group)%>');返回false;>
< IMG ID =imgdiv<%#的eval(reporting_group)%>中WIDTH =15px的边界=0SRC =图像/图标/ plus.jpg/>
&所述; / A>
注意
- 使用
而不是
&放大器; QUOT;
(修正编译错误) - 设置链接的href到
#
- 使用onclick事件执行JavaScript(好习惯)
I want to add an expandable asp grid inside an ASP Panel which I want to make visible/invisible by changing the visible true/false option of the panel.
If I remove asp:Panel ID="test1", the site opens with the exandable gridview working no problem.
Once I've add the code inside the panel I get an error message:
Expression expected.
Source Error:
Line 46: <a href="JavaScript:divexpandcollapse('div<%# Eval("reporting_group") %>');">
Would anyone could explain why it this happening and how to avoid it. I have tried also Ajax TabContainer with the same result.
See code below.
<script language="javascript" type="text/javascript">
function divexpandcollapse(divname) {
var div = document.getElementById(divname);
var img = document.getElementById('img' + divname);
if (div.style.display == "none") {
div.style.display = "block"; img.src = "Images/Icons/minus.jpg";
} else { div.style.display = "none"; img.src = "Images/Icons/plus.jpg"; }
}</script>
<asp:Panel ID="test1" runat="server">
Panel 1<br />
<asp:UpdatePanel ID="UP_TabContainer" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GV_SL" runat="server" AutoGenerateColumns="False"
DataSourceID="SQL_Weekly" OnRowCommand="GV_SL_RowCommand"
OnRowDataBound="gvUserInfo_RowDataBound">
<Columns>
<asp:TemplateField ItemStyle-Width="50px">
<ItemTemplate>
<a href="JavaScript:divexpandcollapse('div<%# Eval("reporting_group") %>');">
<img id="imgdiv<%# Eval("reporting_group") %>" width="15px" border="0" src="Images/Icons/plus.jpg" />
</a>
</ItemTemplate><ItemStyle Width="40px" />
</asp:TemplateField>
<asp:BoundField DataField="name" HeaderText="Group" SortExpression="name" />
<asp:BoundField DataField="ASL" HeaderText="SL% Act" ReadOnly="True" />
<asp:TemplateField>
<ItemTemplate>
<tr>
<td >
<div ID='div<%# Eval("reporting_group") %>' style="display: none; position: relative;
left: 15px; overflow: auto">
<asp:GridView ID="gvChildGrid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Metric"
HeaderText=" "/>
<asp:BoundField DataField="Actual" HeaderText="Actual" />
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:SqlDataSource ID="SQL_Weekly" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand=" SQL QUERY" <SelectParameters>
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SQL_Group" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand=" SQL QUERY" ></asp:SqlDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DateSelection"
EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<br />
</asp:Panel>
try changing the way your link triggers JavaScript to something like this:
<a href="#" onclick="divexpandcollapse('div<%# Eval("reporting_group") %>');return false;">
<img id="imgdiv<%# Eval("reporting_group") %>" width="15px" border="0" src="Images/Icons/plus.jpg" />
</a>
Note:
- use
"
instead of"
(fixes compilation error) - set the link href to
"#"
- use the onclick event to execute JavaScript (good practice)
.
这篇关于ASP面板内部扩展的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!