2013-12-21 127 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 
相關問題