如上圖紅框,你要勾選AutoPostBack,這樣選好DropDownList時,會觸發PostBack刷新網頁,GridView的SelectCommand會自動觸發,完成資料擷取及顯示在GridView中。
如果選了AutoPostBack還是沒動作,看一下GridView的相關設置是否會自動刷新。
你好: Autopostback 已啟用 仍然沒反應
我試作...
結果...
程式碼...分兩個回應給你參考...
<pre class="c" name="code"><asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="kubun" DataValueField="kubun">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="vesion" DataValueField="vesion">
</asp:DropDownList>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3">
<Columns>
<asp:BoundField DataField="NAME" HeaderText="NAME" SortExpression="NAME" />
<asp:BoundField DataField="KUBUN" HeaderText="KUBUN" SortExpression="KUBUN" />
<asp:BoundField DataField="VESION" HeaderText="VESION" SortExpression="VESION" />
</Columns>
</asp:GridView>
<pre class="c" name="code"><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" SelectCommand="SELECT DISTINCT [kubun] FROM [v_item]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" SelectCommand="SELECT [kubun], [vesion] FROM [v_item] WHERE ([kubun] = @kubun)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="kubun" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<pre class="c" name="code"><asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" SelectCommand="SELECT * FROM [v_item] WHERE (([KUBUN] = @KUBUN) AND ([VESION] = @VESION))">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="KUBUN" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="DropDownList2" Name="VESION" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
以上提供你參考.
找到了,非常感謝您的協助!! 已解決!!
Great!!