问题描述
我有两个下拉列表,并在一个asp.net页面的GridView(lstDivisions,lstDistricts,gridIncidents),我使用的SqlDataSource ID报表ASPX页面检索从SQL Server中的数据为所有三个控件。
所有的控件加载正确的,当我在第二个下拉菜单中选择不同的值在GridView填充预期。
当我选择第一个下拉第二个下拉正确填充新科值,但在GridView不会刷新,直到我从第二个下拉列表中选择新会区值。
用什么方法做我用它来刷新GridView的?
感谢
从aspx页面code:
< ASP:SqlDataSource的ID =sourceIncidents=服务器的ProviderName =System.Data.SqlClient的
的ConnectionString =下;%$的ConnectionStrings:DB1Connection%>中
的SelectCommand =SELECT incidentnumber,call_date,call_time,地址,CALL_TYPE,区,距离事故ORDER BY CREATE_DATE
FilterEx pression =区='{0}'EnableCaching =真>
< FilterParameters>
< ASP:ControlParameter控件ID =lstDistrictsNAME =区属性名=的SelectedValue/>
< / FilterParameters>
< / ASP:SqlDataSource的> < ASP:SqlDataSource的ID =sourceIncidentDistricts=服务器
的ProviderName =System.Data.SqlClient的的ConnectionString =<%$的ConnectionStrings:的DB2Connection%>中
的SelectCommand =SELECT DivisionName,DistrictName作为区,距离LEFT JOIN区分部ON Districts.DivisionID = Divisions.DivisionID
FilterEx pression =DivisionName ='{0}'EnableCaching =真>
< FilterParameters>
< ASP:ControlParameter控件ID =lstDivisionsNAME =DivisionName属性名=的SelectedValue/>
< / FilterParameters>
< / ASP:SqlDataSource的> < ASP:SqlDataSource的ID =sourceIncidentDivisions=服务器
的ProviderName =System.Data.SqlClient的的ConnectionString =<%$的ConnectionStrings:的DB2Connection%>中
的SelectCommand =SELECT DISTINCT DivisionName FROM师EnableCaching =真>
< / ASP:SqlDataSource的>
< BR /> < ASP:标签ID =lblDivision=服务器文本=司>< / ASP:标签>
< ASP:DropDownList的ID =lstDivisions=服务器的DataSourceID =sourceIncidentDivisions
DataValueField =DivisionNameOnSelectedIndexChanged =GetDivisions_SelectedIndexChanged
DataTextField =DivisionNameWIDTH =205px的AutoPostBack =真>
< / ASP:DropDownList的> &安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;
< ASP:标签ID =lblDistrict=服务器文本=区>< / ASP:标签>
< ASP:DropDownList的ID =lstDistricts=服务器的DataSourceID =sourceIncidentDistricts
DataValueField =区OnSelectedIndexChanged =GetDistricts_SelectedIndexChanged
DataTextField =区WIDTH =205px的AutoPostBack =真>
< / ASP:DropDownList的>< BR />
< BR />
< ASP:标签ID =lblIncidentsCaption=服务器FONT-粗体=真FONT-名称=宋体
字体大小=小>< / ASP:标签>
< BR /> < ASP:GridView控件ID =gridIncidents=服务器的cellpadding =3的DataSourceID =sourceIncidents
字体名称=宋体FONT-SIZE =小
OnSelectedIndexChanged =gridIncidents_SelectedIndexChanged
网格线=水平的AutoGenerateColumns =FALSE的DataKeyNames =incidentnumber
AllowPaging =真AllowSorting =真背景色=白BORDERCOLOR =#4A3C8C
边框样式=无边框宽度=1像素
PagerSettings模式=NumericFirstLastPagerSettings-位置=TopAndBottom>
< FooterStyle背景色=#B5C7DE前景色=#4A3C8C/>
< RowStyle的BackColor =#E7E7FF前景色=#4A3C8C/>
< PagerStyle背景色=#E7E7FF前景色=#4A3C8CHorizontalAlign =中心/>
< SelectedRowStyle背景色=#738A9CFONT-粗体=真前景色=#F7F7F7/>
< HeaderStyle背景色=#4B6C9EFONT-粗体=真前景色=#F7F7F7/>
< AlternatingRowStyle背景色=#F7F7F7/>
<柱体和GT;
< ASP:CommandField中SelectText =>中ShowSelectButton =真/> < ASP:的TemplateField的HeaderText =九一八事变SORTEX pression =incidentnumber>
<&ItemTemplate中GT;<%#的eval(incidentnumber)的ToString()%方式>< / ItemTemplate中>
< ItemStyle边框宽度=1px的/>
< / ASP:的TemplateField>
< ASP:的TemplateField的HeaderText =DATESORTEX pression =call_date>
<&ItemTemplate中GT;<%#的eval(call_date,{0:MM / DD / YYYY})%GT;< / ItemTemplate中>
< ItemStyle边框宽度=1px的/>
< / ASP:的TemplateField>
< ASP:的TemplateField的HeaderText =TIMESORTEX pression =call_time>
<&ItemTemplate中GT;<%#的eval(call_time)%>< / ItemTemplate中>
< ItemStyle边框宽度=1px的/>
< / ASP:的TemplateField>
< ASP:的TemplateField的HeaderText =ADDRESSSORTEX pression =地址>
<&ItemTemplate中GT;<%#的eval(地址)%GT;< / ItemTemplate中>
< ItemStyle WIDTH =300像素边框宽度=1px的/>
< / ASP:的TemplateField>
< ASP:的TemplateField的HeaderText =呼叫类型SORTEX pression =CALL_TYPE>
<&ItemTemplate中GT;<%#的eval(CALL_TYPE)%>< / ItemTemplate中>
< ItemStyle边框宽度=1px的/>
< / ASP:的TemplateField>
< ASP:的TemplateField的HeaderText =区SORTEX pression =区>
<&ItemTemplate中GT;<%#的eval(区)%GT;< / ItemTemplate中>
< ItemStyle边框宽度=1px的/>
< / ASP:的TemplateField>
< /专栏>
< / ASP:GridView的>
解决方案
在OnSelectedIndexChanged为 lstDivisions
DropDownList的补充: lstDistricts.DataBind();
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>
Solution
In the OnSelectedIndexChanged for the lstDivisions
DropDownList added: lstDistricts.DataBind();
这篇关于ASP.NET的GridView与级联下拉控件刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!