从ListBox.DataTextField中选择值并在TextBox1.text中显示结果, - VS VB ASP.NET Web应用程序 - 该应用程序将从DropDownList中选择一台机器,然后在列表框中显示(可能的)错误代码列表(它到目前为止工作),当选择错误值时,它会在Textbox.text中显示值描述(这一点我无法工作)。
到目前为止,我有以下代码,除了textbox1.text之外,我可以加载Dropdownlist然后它显示ListBox中的代码,但是我无法在文本框中显示故障描述。
数据表在.mdb文件中设置如下
2300Nc | 2300Nr | 2400Nc | 2400Nr | 2500c | 2500r等..
代码|故障描述|代码|故障描述|代码`|错误描述
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim MN = DropDownList1.SelectedItem.Text 'Takes the combobox item, i.e.'2300N and stores it as MN'
Dim code As String
Dim result As String
code = MN & "c" ' Appends the letter c to the end of the sting (
result = MN & "r" ' The Code description.
ListBox1.DataTextField = code ' This bit works great.
TextBox1.Text = "???????" ' In VB I would use TextBox1.DataBindings.Add("text", mYBindingSource, result)
End Sub
我已将TextBox1上的数据绑定如下;
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="TC" runat="server" ConnectionString="<%$ ConnectionStrings:TroublecodesConnectionString %>" ProviderName="<%$ ConnectionStrings:TroublecodesConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [TC]"></asp:SqlDataSource>
<asp:SqlDataSource ID="ModelNo" runat="server" ConnectionString="<%$ ConnectionStrings:ModelConnectionString %>" ProviderName="<%$ ConnectionStrings:ModelConnectionString.ProviderName %>" SelectCommand="SELECT [Model Number] AS Model_Number FROM [Table1]"></asp:SqlDataSource>
<br />
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ModelNo" DataTextField="Model_Number" DataValueField="Model_Number">
</asp:DropDownList>
<br />
<asp:ListBox ID="ListBox1" runat="server" DataSourceID="TC" Width="128px"></asp:ListBox>
<asp:Button ID="Button2" runat="server" Text="Button" />
<br />
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("TC") %>'></asp:TextBox>
<br />
</div>
</form>
非常感谢任何帮助。
由于
答案 0 :(得分:0)
这更像是一个评论,但我还没有能力。你试过了吗?
TextBox1.Text = result