Genpact Cora Knowledge Center

Support

Pass Parameters from the Main Form to a Sub View

NOTE
This feature is available from v7.7 and above.

You can pass parameters from a form to its sub view. For example, you have a sub view, which displays records of employees, and in the parent form there is a combo box, where the user can select an employee. You want the sub view to display the details of the selected employee.

Passing Parameters to Sub View

You can do so using the following code:

Main Form:

<%@ Control %>
<table class="sqf-main-table" cellpadding="0" cellspacing="0">
<tr>
<td>
<sq:Label runat="server" Text="Select Employee:" Width="100px" />
<sq:DataSource runat="server" ID="DataSource1" QueryName="ViewEmployees"></sq:DataSource>
<sq:ComboBox runat="server" ID="ComboBox1" DataSourceID="DataSource1" AutoPostBack="true" DataTextField="Name" DataValueField="Id" EnableAutomaticLoadOnDemand="True" ShowMoreResultsBox="True" ItemsPerRequest="10"></sq:ComboBox>
</td>
</tr>
<tr>
<td>
<sq:SubView runat="server" ID="SubView1" VirtualPath="../UserDetails/DefaultView.ascx" Skin="Default"> <Parameters> <asp:ControlParameter Name="EmployeeId" ControlID="ComboBox1" DbType="Int32" /> </Parameters>
</sq:SubView>
</td>
</tr>
</table>

Sub View:

<%@ Control %>
<sq:Form runat="server" ID="tblEmployeesForm" DataKeyNames="fldEmployeeId"
DataSourceID="tblEmployeesDataSource" ReadOnly="true" CellPadding="0" CellSpacing="0" Height="217px"><ContentTemplate>
<table class="sqf-section-table" cellpadding="0" cellspacing="0">
<tr>
<td class="sqf-section-header" colspan="2">
<h2><sq:Text runat="server" Text="Employee Details"></sq:Text></h2>
</td>
</tr>
<tr>
<td>
<sq:Label runat="server" Text="ID" />
</td>
<td>
<sq:Label runat="server" ID="fldEmployeeId"></sq:Label>
<sq:BindableControl runat="server" TargetControlID="fldEmployeeId" DataField="fldEmployeeId"></sq:BindableControl>
</td>
</tr>
<tr>
<td>
<sq:Label runat="server" Text="First Name" />
</td>
<td>
<sq:Label runat="server" ID="fldEmpName"></sq:Label>
<sq:BindableControl runat="server" TargetControlID="fldEmpName" DataField="fldEmpName"></sq:BindableControl>
</td>
</tr>
<tr>
<td>
<sq:Label runat="server" Text="Last Name" />
</td>
<td>
<sq:Label runat="server" ID="fldEmpLastName"></sq:Label>
<sq:BindableControl runat="server" TargetControlID="fldEmpLastName" DataField="fldEmpLastName"></sq:BindableControl>
</td>
</tr>
<tr>
<td>
<sq:Label runat="server" Text="Username" />
</td>
<td>
<sq:Label runat="server" ID="fldEmpUseName"></sq:Label>
<sq:BindableControl runat="server" TargetControlID="fldEmpUseName" DataField="fldEmpUseName"></sq:BindableControl>
</td>
</tr>
<tr>
<td>
<sq:Label runat="server" Text="Email" />
</td>
<td>
<sq:Label runat="server" ID="fldEmail"></sq:Label>
<sq:BindableControl runat="server" TargetControlID="fldEmail" DataField="fldEmail"></sq:BindableControl>
</td>
</tr>
</table>
</ContentTemplate>
</sq:Form>
<sq:DataSource runat="server" ID="tblEmployeesDataSource" QueryName="tblEmployees" Where="fldEmployeeId == @fldEmployeeId"><WhereParameters> <sq:TemplateControlParameter PropertyName="Parameters[&quot;EmployeeId&quot;]" Name="fldEmployeeId"></sq:TemplateControlParameter> </WhereParameters>
</sq:DataSource>
<sq:BoundControl runat="server" TargetControlID="tblEmployeesForm"></sq:BoundControl>