I have two dropdowns and a gridview (lstDivisions, lstDistricts, gridIncidents) in an asp.net page and I use SqlDataSource ID statements in the ASPX page to retrieve the data from SQL Server for all three controls.
All controls load properly and when I select a different value in the second dropdown the gridview populates as expected.
When I select a new Division value in the first dropdown the second dropdown populates properly BUT the gridview does not refresh UNTIL I select a new District value from the second dropdown.
What method do I use to Refresh the gridview?
Thanks
Code from aspx page:
<asp:SqlDataSource ID="sourceIncidents" runat="server" ProviderName="System.Data.SqlClient"
ConnectionString="<%$ ConnectionStrings:DB1Connection %>"
SelectCommand="SELECT incidentnumber, call_date, call_time, address , call_type, district FROM Incident ORDER BY create_date"
FilterExpression="District='{0}'" EnableCaching="True">
<FilterParameters>
<asp:ControlParameter ControlID="lstDistricts" Name="district" PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sourceIncidentDistricts" runat="server"
ProviderName="System.Data.SqlClient" ConnectionString="<%$ ConnectionStrings:DB2Connection %>"
SelectCommand="SELECT DivisionName, DistrictName as District FROM Divisions LEFT JOIN Districts ON Districts.DivisionID = Divisions.DivisionID"
FilterExpression="DivisionName ='{0}'" EnableCaching="True">
<FilterParameters>
<asp:ControlParameter ControlID="lstDivisions" Name="DivisionName" PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sourceIncidentDivisions" runat="server"
ProviderName="System.Data.SqlClient" ConnectionString="<%$ ConnectionStrings:DB2Connection %>"
SelectCommand="SELECT DISTINCT DivisionName FROM Divisions" EnableCaching="True">
</asp:SqlDataSource>
<br />
<asp:Label ID="lblDivision" runat="server" Text="Division"></asp:Label>
<asp:DropDownList ID="lstDivisions" runat="server" DataSourceID="sourceIncidentDivisions"
DataValueField="DivisionName" OnSelectedIndexChanged="GetDivisions_SelectedIndexChanged"
DataTextField="DivisionName" Width="205px" AutoPostBack="True">
</asp:DropDownList>
<asp:Label ID="lblDistrict" runat="server" Text="District"></asp:Label>
<asp:DropDownList ID="lstDistricts" runat="server" DataSourceID="sourceIncidentDistricts"
DataValueField="District" OnSelectedIndexChanged="GetDistricts_SelectedIndexChanged"
DataTextField="District" Width="205px" AutoPostBack="True">
</asp:DropDownList><br />
<br />
<asp:Label ID="lblIncidentsCaption" runat="server" Font-Bold="True" Font-Names="Verdana"
Font-Size="Small"></asp:Label>
<br />
<asp:GridView ID="gridIncidents" runat="server" CellPadding="3" DataSourceID="sourceIncidents"
Font-Names="Verdana" Font-Size="Small"
OnSelectedIndexChanged="gridIncidents_SelectedIndexChanged"
GridLines="Horizontal" AutoGenerateColumns="False" DataKeyNames="incidentnumber"
AllowPaging="True" AllowSorting="True" BackColor="White" BorderColor="#4A3C8C"
BorderStyle="None" BorderWidth="1px"
PagerSettings-Mode="NumericFirstLast" PagerSettings-Position="TopAndBottom" >
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4B6C9E" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
<Columns>
<asp:CommandField SelectText=">" ShowSelectButton="True" />
<asp:TemplateField HeaderText="INCIDENT" SortExpression="incidentnumber">
<ItemTemplate><%# Eval("incidentnumber").ToString() %></ItemTemplate>
<ItemStyle BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="DATE" SortExpression="call_date">
<Itemtemplate><%# Eval("call_date", "{0:MM/dd/yyyy}")%></Itemtemplate>
<ItemStyle BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="TIME" SortExpression="call_time">
<Itemtemplate><%# Eval("call_time") %></Itemtemplate>
<ItemStyle BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="ADDRESS" SortExpression="address">
<Itemtemplate><%# Eval("address") %></Itemtemplate>
<ItemStyle Width="300px" BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="CALL TYPE" SortExpression="call_type">
<Itemtemplate><%# Eval("call_type") %></Itemtemplate>
<ItemStyle BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="DISTRICT" SortExpression="district">
<Itemtemplate><%# Eval("district")%></Itemtemplate>
<ItemStyle BorderWidth="1px" />
</asp:TemplateField>
</Columns>
</asp:GridView>