Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在列表框中的文本框中显示文本-ASP.net和VB.net_Asp.net_Vb.net_Listbox - Fatal编程技术网

在列表框中的文本框中显示文本-ASP.net和VB.net

在列表框中的文本框中显示文本-ASP.net和VB.net,asp.net,vb.net,listbox,Asp.net,Vb.net,Listbox,ASP.net代码列表框 <asp:ListBox class="mailList" ID="ListBox1" runat="server" SelectionMode="Multiple" > <asp:ListItem Value="0">Welcome to PVAL Portal</asp:ListItem> <asp:ListItem Value="1">Reminder&l

ASP.net代码列表框

<asp:ListBox class="mailList" ID="ListBox1" runat="server" 
          SelectionMode="Multiple" >
          <asp:ListItem Value="0">Welcome to PVAL Portal</asp:ListItem>
          <asp:ListItem Value="1">Reminder</asp:ListItem>
          <asp:ListItem Value="2">User2</asp:ListItem>
</asp:ListBox>
当我运行程序并从列表框中选择任何项目时,它没有在文本框中显示文本。我通过添加一个按钮来解决这个问题。但我真的不喜欢它。我只是想知道,在我从列表框中选择一个项目后,是否有任何方法可以直接在文本框中显示文本而不使用按钮


提前谢谢你,谢谢你

在asp.net列表框的html中添加Autopostback=true。因为现在更改选择时列表框不会回发

<asp:ListBox class="mailList" ID="ListBox1" runat="server" 
      SelectionMode="Multiple" AutoPostBack="true">
      <asp:ListItem Value="0">Welcome to PVAL Portal</asp:ListItem>
      <asp:ListItem Value="1">Reminder</asp:ListItem>
      <asp:ListItem Value="2">User2</asp:ListItem>
</asp:ListBox>

您应该在列表框中将AutoPostBack属性设置为true

Protected Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
    Dim curItem As String = ListBox1.SelectedIndex()

    If curItem = 0 Then
        messageTitle.Text = "Testing1"
        messageText.Text = "Hello"
    ElseIf curItem = 1 Then
        messageTitle.Text = "Testing2"
        messageText.Text = "Hello2"
    ElseIf curItem = 2 Then
         messageTitle.Text = "Testing3"
        messageText.Text = "Hello3"
    End If
End Sub
<asp:ListBox class="mailList" ID="ListBox1" runat="server" 
      SelectionMode="Multiple" AutoPostBack="true">
      <asp:ListItem Value="0">Welcome to PVAL Portal</asp:ListItem>
      <asp:ListItem Value="1">Reminder</asp:ListItem>
      <asp:ListItem Value="2">User2</asp:ListItem>
</asp:ListBox>