Queryextender control is a control
that helps in doing actions like filtration, searching, sorting etc. on the LINQ
Data source with few steps. In fact we don’t have to write any code with this.
Screenshot given below is just an example that can easily be achieved through this control.
In the above screenshot, we can see that there is a GridView Control that has been binded to a LINQData Source Control. And we have a DropDownlistBox that is also binded to another LINQData Source Control and displaying only grouped jobs. The GridView display all the employees who are matching the Job Parameter. This is done through QueryExtender Control. Also we can search for any name in the employee name's through Query Extender control. The code in the HTML goes like:
<form id="form1" runat="server">
<div>
Select Job: <asp:DropDownList ID="Job" runat="server" DataSourceID="LinqDataSource2"
DataTextField="JOB" DataValueField="JOB" Width="300px" AutoPostBack="True"></asp:DropDownList>
<asp:LinqDataSource ID="LinqDataSource2" runat="server" ContextTypeName="EmployeeDataContext" EntityTypeName="" GroupBy="JOB" Select="new (key as JOB, it as EMPs)" TableName="EMPs">
</asp:LinqDataSource>
Search Name:
<asp:TextBox ID="TextBox1" runat="server"Width="273px"></asp:TextBox>
<br />
Now the code in html for GridView and LINQData Source.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataSourceID="LinqDataSource1" Height="215px" Width="765px" ForeColor="Black" GridLines="Vertical">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:BoundField DataField="EMPNO" HeaderText="EMPNO" SortExpression="EMPNO" />
<asp:BoundField DataField="ENAME" HeaderText="ENAME" SortExpression="ENAME" />
<asp:BoundField DataField="JOB" HeaderText="JOB" SortExpression="JOB" />
<asp:BoundField DataField="MGR" HeaderText="MGR" SortExpression="MGR" />
<asp:BoundField DataField="HIREDATE" HeaderText="HIREDATE" SortExpression="HIREDATE" />
<asp:BoundField DataField="SAL" HeaderText="SAL" SortExpression="SAL" />
<asp:BoundField DataField="COMM" HeaderText="COMM" SortExpression="COMM" />
<asp:BoundField DataField="DEPTNO" HeaderText="DEPTNO" SortExpression="DEPTNO" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="EmployeeDataContext"EntityTypeName="" TableName="EMPs">
</asp:LinqDataSource>
<asp:QueryExtender ID="QueryExtender1" runat="server" TargetControlID="LinqDataSource1">
<asp:PropertyExpression>
<asp:ControlParameter ControlID="Job" Name="Job" />
</asp:PropertyExpression>
<asp:SearchExpression ComparisonType="InvariantCultureIgnoreCase"
DataFields="Ename, Job" SearchType="Contains">
<asp:ControlParameter ControlID="TextBox1" />
</asp:SearchExpression>
There are two filters that we have used in the QueryExtender Control.
a.
PropertyExpression: That just matches with anything but
works only for the equality operator.
<asp:PropertyExpression>
<asp:ControlParameter ControlID="Job" Name="Job" />
</asp:PropertyExpression>
The “Name” attribute in the above tag
specifies the name of column from the database.
b. SearchExpression:
That searches for the
given content irrespective of Lowercase of uppercase and in number of fields
<asp:SearchExpression ComparisonType="InvariantCultureIgnoreCase"
DataFields="Ename, Job" SearchType="Contains">
<asp:ControlParameter ControlID="TextBox1" />
Comments