ListItem.Value-Eigenschaft
Ruft den Wert ab, der ListItem zugeordnet ist, oder legt diesen fest.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
<LocalizableAttribute(True)> _
Public Property Value As String
'Usage
Dim instance As ListItem
Dim value As String
value = instance.Value
instance.Value = value
[LocalizableAttribute(true)]
public string Value { get; set; }
[LocalizableAttribute(true)]
public:
property String^ Value {
String^ get ();
void set (String^ value);
}
/** @property */
public String get_Value ()
/** @property */
public void set_Value (String value)
public function get Value () : String
public function set Value (value : String)
Eigenschaftenwert
Der dem ListItem zugeordnete Wert. Der Standardwert ist String.Empty.
Hinweise
Mithilfe der Value-Eigenschaft können Sie den Wert angeben oder bestimmen, der dem ListItem zugeordnet ist.
Hinweis
Wenn die Value-Eigenschaft NULL (Nothing in Visual Basic) enthält, gibt der get-Accessor den Wert der Text-Eigenschaft zurück. Wenn die Text-Eigenschaft ebenfalls NULL (Nothing in Visual Basic) enthält, wird String.Empty zurückgegeben.
Der Wert dieser Eigenschaft (sofern festgelegt) kann mit einem Designertool automatisch in einer Ressourcendatei gespeichert werden. Weitere Informationen finden Sie unter LocalizableAttribute und unter ASP.NET-Globalisierung und -Lokalisierung.
Beispiel
Hinweis
Im folgenden Codebeispiel wird das Einzeldatei-Codemodell verwendet. Das Beispiel funktioniert möglicherweise nicht, wenn es direkt in eine CodeBehind-Datei kopiert wird. Dieses Codebeispiel muss in eine leere Textdatei mit der Erweiterung .aspx kopiert werden. Weitere Informationen über das Web Forms-Codemodell finden Sie unter Codemodell für ASP.NET-Webseiten.
<%@ Page Language="VB" %>
<!-- The following example demonstrates adding items to and removing items
from ListBox controls. When an item is selected in ListBox1, a new ListBoxItem with
the same value can be created and added to ListBox2, if ListBox2 does not already
contain an item with that value. When the new ListBoxItem is created, it receives
the Value property of the selected item as its Text property, and the Text property
of the selected item as its value property. -->
<html>
<head>
<script language="VB" runat="server">
Sub AddBtn_Click(Sender As Object, e As EventArgs)
If ListBox1.SelectedIndex > -1 Then
If ListBox2.Items.FindByValue(ListBox1.SelectedItem.Text) is Nothing Then
Dim Item As ListItem = new ListItem()
'Text and Value are swapped
Item.Text = ListBox1.SelectedItem.Value
Item.Value = ListBox1.SelectedItem.Text
ListBox2.Items.Add(Item)
End If
End If
End Sub
Sub DelBtn_Click(Sender As Object, e As EventArgs)
If ListBox2.SelectedIndex > -1 Then
ListBox2.Items.Remove(ListBox2.SelectedItem)
End If
End Sub
</script>
</head>
<body>
<h3>ListItem Example</h3>
<p>
<form runat=server>
<table>
<tr><td>
<asp:ListBox id=ListBox1 Width="100px" runat="server">
<asp:ListItem Value="Value 1">Item 1</asp:ListItem>
<asp:ListItem Value="Value 2">Item 2</asp:ListItem>
<asp:ListItem Value="Value 3">Item 3</asp:ListItem>
<asp:ListItem Value="Value 4">Item 4</asp:ListItem>
<asp:ListItem Value="Value 5" Selected="True">Item 5</asp:ListItem>
<asp:ListItem Value="Value 6">Item 6</asp:ListItem>
</asp:ListBox>
</td><td>
<asp:button Text="--->" OnClick="AddBtn_Click" runat="server" /><br>
<asp:button Text="<---" OnClick="DelBtn_Click" runat="server" />
</td><td>
<asp:ListBox id=ListBox2 Width="100px" runat="server"/>
</td></tr>
</table>
</form>
</body>
</html>
<!-- The following example demonstrates adding items to and removing items
from ListBox controls. When an item is selected in ListBox1, a new ListBoxItem with
the same value can be created and added to ListBox2, if ListBox2 does not already
contain an item with that value. When the new ListBoxItem is created, it receives
the Value property of the selected item as its Text property, and the Text property
of the selected item as its value property. -->
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
void AddBtn_Click(Object Sender, EventArgs e)
{
if (ListBox1.SelectedIndex > -1)
{
if (ListBox2.Items.FindByValue(ListBox1.SelectedItem.Text) == null)
{
ListItem Item = new ListItem();
// Text and Value are swapped.
Item.Text = ListBox1.SelectedItem.Value;
Item.Value = ListBox1.SelectedItem.Text;
ListBox2.Items.Add(Item);
}
}
}
void DelBtn_Click(Object Sender, EventArgs e)
{
if (ListBox2.SelectedIndex > -1)
{
ListBox2.Items.Remove(ListBox2.SelectedItem);
}
}
</script>
</head>
<body>
<h3>ListItem Example</h3>
<p>
<form runat=server>
<table>
<tr><td>
<asp:ListBox id=ListBox1 Width="100px" runat="server">
<asp:ListItem Value="Value 1">Item 1</asp:ListItem>
<asp:ListItem Value="Value 2">Item 2</asp:ListItem>
<asp:ListItem Value="Value 3">Item 3</asp:ListItem>
<asp:ListItem Value="Value 4">Item 4</asp:ListItem>
<asp:ListItem Value="Value 5" Selected="True">Item 5</asp:ListItem>
<asp:ListItem Value="Value 6">Item 6</asp:ListItem>
</asp:ListBox>
</td><td>
<asp:button Text="--->" OnClick="AddBtn_Click" runat="server" /><br>
<asp:button Text="<---" OnClick="DelBtn_Click" runat="server" />
</td><td>
<asp:ListBox id=ListBox2 Width="100px" runat="server"/>
</td></tr>
</table>
</form>
</body>
</html>
<!-- The following example demonstrates adding items to and removing items
from ListBox controls. When an item is selected in ListBox1, a new ListBoxItem with
the same value can be created and added to ListBox2, if ListBox2 does not already
contain an item with that value. When the new ListBoxItem is created, it receives
the Value property of the selected item as its Text property, and the Text property
of the selected item as its value property. -->
<%@ Page Language="JScript" %>
<html>
<head>
<script language="JScript" runat="server">
function AddBtn_Click(Sender : Object, e : EventArgs)
{
if (ListBox1.SelectedIndex > -1)
{
if (ListBox2.Items.FindByValue(ListBox1.SelectedItem.Text)==null)
{
var Item : ListItem = new ListItem();
// Text and Value are swapped.
Item.Text = ListBox1.SelectedItem.Value;
Item.Value = ListBox1.SelectedItem.Text;
ListBox2.Items.Add(Item);
}
}
}
function DelBtn_Click(Sender : Object, e : EventArgs)
{
if (ListBox2.SelectedIndex > -1)
{
ListBox2.Items.Remove(ListBox2.SelectedItem);
}
}
</script>
</head>
<body>
<h3>ListItem Example</h3>
<p>
<form runat=server>
<table>
<tr><td>
<asp:ListBox id=ListBox1 Width="100px" runat="server">
<asp:ListItem Value="Value 1">Item 1</asp:ListItem>
<asp:ListItem Value="Value 2">Item 2</asp:ListItem>
<asp:ListItem Value="Value 3">Item 3</asp:ListItem>
<asp:ListItem Value="Value 4">Item 4</asp:ListItem>
<asp:ListItem Value="Value 5" Selected="True">Item 5</asp:ListItem>
<asp:ListItem Value="Value 6">Item 6</asp:ListItem>
</asp:ListBox>
</td><td>
<asp:button Text="--->" OnClick="AddBtn_Click" runat="server" /><br>
<asp:button Text="<---" OnClick="DelBtn_Click" runat="server" />
</td><td>
<asp:ListBox id=ListBox2 Width="100px" runat="server"/>
</td></tr>
</table>
</form>
</body>
</html>
Plattformen
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
ListItem-Klasse
ListItem-Member
System.Web.UI.WebControls-Namespace
ListItem.Text-Eigenschaft
ListControl-Klasse
RadioButtonList
ListBox-Klasse
DropDownList-Klasse
CheckBoxList-Klasse
Weitere Ressourcen
ListBox-Webserver-Steuerelement
Übersicht über die RadioButton- und RadioButtonList-Webserversteuerelemente
CheckBox- und CheckBoxList-Webserver-Steuerelemente
BulletedList-Webserver-Steuerelement
DropDownList-Webserversteuerelement