Nathanus Nathanus - 1 year ago 53
ASP.NET (C#) Question

Is it possible to use a control in a different content tag as a parameter?

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"
DataTextField="St" DataValueField="St" RepeatColumns="2">

<asp:Content ID="ResultsPanel" runat="server" ContentPlaceHolderID="RightContent">
<asp:GridView ID="gView1" runat="server"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="TestDS1">
<asp:SqlDataSource ID="TestDS1" runat="server"
SelectCommand="SELECT ST FROM [Table] where ST = ?">
<asp:ControlParameter ControlID="cbList1" Name="?"
PropertyName="SelectedValue" />

It works fine when I put both controls in the same
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?

Answer Source

Apparently this can be done by prefixing the ContentPlaceHolderID to the ControlID of the parameter entry. In my case, the code would be:

        <asp:ControlParameter ControlID="LeftContent:cbList1" Name="?" 
            PropertyName="SelectedValue" />

since the Control the parameter reads from is in the LeftContent tag.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download