2013-12-21 88 views

回答

2

试试这个

你需要写在组合框中的selectedIndex更改事件的代码

如:

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged 
     Label1.Text= DropDownList1.SelectedItem.Text.ToString() 
End Sub 

和你需要在PageLoad中设置DropDownList.AutoPostBack=true事件

+0

combobox.SelectedItem.Text错误,但是combobox.SelectedItem没有。仍然帮我弄明白了,谢谢 – user3105998

+0

我已经更新了解决方案。请检查这个 –

+0

我使用它作为If语句,并且发现这对我来说工作正常:如果combobox.SelectedItem =“Text” – user3105998

1

变化取决于您的控件..

Private Sub YourComboBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YourComboBox.Click 

    UrLabel.Text = YourComboBox.SelectedValue 

End Sub 
0

Asp.net

组合框

您需要设置的AutoPostBack = “真”

<table> 
      <tr> 
       <td><asp:ComboBox ID="cmb" runat="server" AutoPostBack="True"> 
      <asp:ListItem>1</asp:ListItem> 
      <asp:ListItem>2</asp:ListItem> 
      </asp:ComboBox></td> 

     <td> 
      <asp:Label ID="lbl" runat="server"></asp:Label> 
     </td> 
      </tr> 
     </table> 

.aspx文件(代码后面)

Protected Sub cmb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmb.SelectedIndexChanged 
     lbl.Text = cmb.SelectedValue 
    End Sub 

Asp.net

的DropDownList

您需要设置的AutoPostBack = “真”

<table> 
      <tr> 
       <td><asp:DropDownList ID="ddl" runat="server" AutoPostBack="True"> 
      <asp:ListItem>1</asp:ListItem> 
      <asp:ListItem>2</asp:ListItem> 
      </asp:DropDownList></td> 

     <td> 
      <asp:Label ID="lbl" runat="server"></asp:Label> 
     </td> 
      </tr> 
     </table> 

.aspx文件(代码后面)

Protected Sub ddl_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddl.SelectedIndexChanged 
     lbl.Text = ddl.SelectedValue 
    End Sub 
相关问题