ASP.NET:在为一个字段查询SQL Server时,使用数据库中的值自动填充另一个字段

时间:2021-08-15 09:08:35

This is the markup I have

这是我的标记

<td>
    <asp:ComboBox ID="cbArtikal" runat="server" AppendDataBoundItems="True" 
           AutoCompleteMode="Suggest" DataSourceID="ssArtikal" 
           DataTextField="Artikal" DataValueField="Artikal" MaxLength="0" 
           style="display: inline;">
     </asp:ComboBox>
     <asp:SqlDataSource ID="ssArtikal" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT [Artikal] FROM [Stavke_Dokumenta]">
      </asp:SqlDataSource>
</td>
<td>
       <asp:ComboBox ID="cbJM" runat="server" AppendDataBoundItems="True" 
              AutoCompleteMode="Suggest" DataSourceID="ssJM" DataTextField="JM" 
              DataValueField="JM" MaxLength="0" style="display: inline;">
        </asp:ComboBox>
        <asp:SqlDataSource ID="ssJM" runat="server" 
              ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
              SelectCommand="SELECT [JM] FROM [Stavke_Dokumenta]"></asp:SqlDataSource>
</td>

What I would like is to do is autofill the second field when first one is selected, but to still have the option to change the value with dropbox.

我想要做的是在选择第一个字段时自动填充第二个字段,但仍然可以选择使用dropbox更改值。

1 个解决方案

#1


0  

You can create an OnChange event on the first combobox, with something like:

您可以在第一个组合框上创建一个OnChange事件,例如:

cbJM.SelectedItem = cbArtikal.Items.SelectedItem;

Or take this approach:

或采取这种方法:

cbJM.SelectedItem = cbArtikal.Items.FindByValue("The Selected Value")

#1


0  

You can create an OnChange event on the first combobox, with something like:

您可以在第一个组合框上创建一个OnChange事件,例如:

cbJM.SelectedItem = cbArtikal.Items.SelectedItem;

Or take this approach:

或采取这种方法:

cbJM.SelectedItem = cbArtikal.Items.FindByValue("The Selected Value")