.net中怎么实现下拉框多选,然后获取选中的值 10
您可以选择使用CheckListBox控件。CheckListBox支持多选。
由于不清楚您用什么语言,所以我写了VB.net 、C#.net
vb.net Code
' Determine if there are any items checked.
If CheckedListBox1.CheckedItems.Count <> 0 Then
' If so, loop through all checked items and print results.
Dim x As Integer
Dim s As String = ""
For x = 0 To CheckedListBox1.CheckedItems.Count - 1
s = s & "Checked Item " & (x + 1).ToString & " = " & CheckedListBox1.CheckedItems(x).ToString & ControlChars.CrLf
Next x
MessageBox.Show(s)
End If
C#.net Code
// Determine if there are any items checked.
if(checkedListBox1.CheckedItems.Count != 0)
{
// If so, loop through all checked items and print results.
string s = "";
for(int x = 0; x <= checkedListBox1.CheckedItems.Count - 1 ; x++)
{
s = s + "Checked Item " + (x+1).ToString() + " = " + checkedListBox1.CheckedItems[x].ToString() + "\n";
}
MessageBox.Show (s);
}
vb.net Code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim selectstr As String = ""
For i As Integer = 0 To Me.CheckedListBox1.Items.Count - 1
If Me.CheckedListBox1.GetItemChecked(i) Then
selectstr &= Me.CheckedListBox1.Items(i).ToString
End If
Next
MsgBox(selectstr)
End Sub
希望能帮到您。
又不是说javascript
而且你也不知道是不是asp.net
肯定是asp.net啊