The final configuration needed is the UpdatePanel control. Since
now the GridView is dependent on the user’s selection from the DropDownList, it
must refresh when the selection changes. The good news is that the UpdatePanel
provides you with this functionality using the <Triggers> tag.
Listing 6 – Triggers Tag in Update Panel Control
<atlas:UpdatePanel ID="up1" runat="server" >
<Triggers>
<atlas:ControlValueTrigger ControlID="ddlCity" PropertyName="SelectedValue" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="gvContacts" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
BackColor="White" BorderColor="#DEDFDE"
BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataSourceID="SqlDataSource1"
ForeColor="Black" GridLines="Vertical" >
<FooterStyle BackColor="#CCCC99" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Address"
HeaderText="Address" SortExpression="Address" />
</Columns>
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</ContentTemplate>
</atlas:UpdatePanel>
Analysis
All the code that you see above is the same except for the
<Triggers> tag. <Triggers> allows you to make the UpdatePanel
dependent on other controls, which in this case is the DropDownList control. Now,
anytime you make a selection in the DropDownList control it will refresh the
UpdatePanel control thus refreshing the GridView.
Downloads
[Download Sample]