问题描述
我现在有两个Web控件,一个是的CheckBoxList,另外一个GridView。 GridView的数据配置有在它的查询参数链接到从的CheckBoxList选中的值。然而,当这两个控制是在像这样单独的内容标签:
I currently have two Web Controls, one being a CheckBoxList, and the other a GridView. The GridView's data configuration has a parameter in it's query which is linked to the selected values from the CheckBoxList. However, when the two controls are in separate content tags like so:
<asp:Content ID="ListPanel" runat="server" ContentPlaceHolderID="LeftContent">
<h3>Pick Info Here</h3>
<asp:CheckBoxList ID="cbList1" runat="server"
DataSourceID="TestDataSource"
DataTextField="St" DataValueField="St" RepeatColumns="2">
</asp:CheckBoxList>
</asp:Content>
<asp:Content ID="ResultsPanel" runat="server" ContentPlaceHolderID="RightContent">
<asp:GridView ID="gView1" runat="server"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="TestDS1">
<Columns>
...
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="TestDS1" runat="server"
...
SelectCommand="SELECT ST FROM [Table] where ST = ?">
<SelectParameters>
<asp:ControlParameter ControlID="cbList1" Name="?"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
它正常工作,当我把两个控件在同一&LT; ASP:内容&GT;
标记,但事情系统的错误调用分开.InvalidOperationException:找不到控制'cbList1在ControlParameter
?。有没有一种方法,以保持控制分开,或者他们必须是相同的内容标签内?
It works fine when I put both controls in the same <asp:Content>
tag, but things call apart with an error of System.InvalidOperationException: Could not find control 'cbList1' in ControlParameter '?'
. Is there a way to keep the controls separate, or do they have to be inside the same content tag?
推荐答案
显然,这可以通过prefixing要做的 ContentPlaceHolderID
到控件ID
参数输入的。在我的例子中,code将是:
Apparently this can be done by prefixing the ContentPlaceHolderID
to the ControlID
of the parameter entry. In my case, the code would be:
SelectParameters>
<asp:ControlParameter ControlID="LeftContent:cbList1" Name="?"
PropertyName="SelectedValue" />
</SelectParameters>
由于控制参数从读取是在LeftContent标签。
since the Control the parameter reads from is in the LeftContent tag.
这篇关于是否有可能在不同的内容标签作为参数使用控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!