我有一個連接到數據源的DropDownList控件的問題。我想在編輯完整的formview時顯示選定的索引,但每次我嘗試編輯時,我都會得到表格的第一個索引...而選擇的索引是不同的..我嘗試使用selectparameters,但它也不起作用! 這是我的代碼。DropDownList datasource asp.net vb
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="DDListDataSource" DataTextField="GradeGroupName" DataValueField="GradeGroupName" Height="18px" Width="164px" >
</asp:DropDownList>
<asp:SqlDataSource ID="DDListDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:Dev201601ConnectionString %>"
InsertCommand="INSERT INTO GradeGroups(GradeGroup) VALUES (@GradeGroup)"
SelectCommand="SELECT GradeGroupName FROM GradeGroups"
UpdateCommand="UPDATE GradeGroups SET GradeGroupName = @GradeGroup, GradeGroup = @GradeGroup WHERE (GradeGroup = @Original_GradeGroup)">
<InsertParameters>
<asp:Parameter Name="GradeGroup"></asp:Parameter>
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="GradeGroupName" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="GradeGroupName" />
<asp:Parameter Name="GradeGroup" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="GradeGroup" />
<asp:Parameter Name="Original_GradeGroup" />
</UpdateParameters>
</asp:SqlDataSource>
嘗試將AutoPostBack =「false」添加到您的下拉列表控件中 – Khazratbek
我還有一個問題:爲什麼要使用兩次InsertParameters? – Khazratbek