如何根据 SQLDataReader 值在组合框中选择值。
ASP 代码:
<asp:SqlDataSource ID="PREFERENCE_DS" runat="server"
ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionStringTEST %>"
SelectCommand="SELECT [ID], [NAME] FROM [OBJECTS] WHERE ([CLASSID] = @CLASSID) UNION ALL SELECT NULL, ' Нет'">
<SelectParameters>
<asp:Parameter DefaultValue="3" Name="CLASSID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<dx:ASPxComboBox ID="PREFERENCE" runat="server" SelectedIndex="0" Width="430px"
ClientInstanceName="preference" AutoPostBack="True"
DataSourceID="PREFERENCE_DS" TextField="NAME" TextFormatString="{0}"
ValueField="ID">
<Columns>
<dx:ListBoxColumn FieldName="ID" Visible="False" />
<dx:ListBoxColumn Caption="Преференция" FieldName="NAME" />
</Columns>
</dx:ASPxComboBox>
我试试
PREFERENCE.Value = reader["PREFERENCE"];
和
if (reader["PREFERENCE"] != null)
PREFERENCE.Text = reader["PREFERENCE"].ToString();
else
PREFERENCE.SelectedIndex = PREFERENCE.Items.FindByValue(DBNull.Value).Index;
但它不起作用。