ListBox.SelectionMode Özellik

Tanım

Denetimin seçim modunu ListBox alır veya ayarlar.

public:
 virtual property System::Web::UI::WebControls::ListSelectionMode SelectionMode { System::Web::UI::WebControls::ListSelectionMode get(); void set(System::Web::UI::WebControls::ListSelectionMode value); };
public virtual System.Web.UI.WebControls.ListSelectionMode SelectionMode { get; set; }
member this.SelectionMode : System.Web.UI.WebControls.ListSelectionMode with get, set
Public Overridable Property SelectionMode As ListSelectionMode

Özellik Değeri

ListSelectionMode

Değerlerden ListSelectionMode biri. Single varsayılan değerdir.

Özel durumlar

Belirtilen seçim modu değerlerden ListSelectionMode biri değil.

Örnekler

Aşağıdaki örnekte, kullanıcının denetimden birden çok seçim seçmesine izin vermek için özelliğinin ListBox nasıl kullanılacağı SelectionMode gösterilmektedir.


<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ListBox Example</title>
<script runat="server">

      void SubmitBtn_Click(Object sender, EventArgs e) 
      {

         Message.Text = "You chose: <br />";
         
         // Iterate through the Items collection of the ListBox and 
         // display the selected items.
         foreach (ListItem item in ListBox1.Items)
         {

            if(item.Selected)
            {

               Message.Text += item.Text + "<br />";

            }

         }

      }

   </script>

</head>
<body>

   <h3>ListBox Example</h3>

   <form id="form1" runat="server">

      Select items from the list and click Submit. <br />

      <asp:ListBox id="ListBox1" 
           Rows="6"
           Width="100px"
           SelectionMode="Multiple" 
           runat="server">

         <asp:ListItem Selected="True">Item 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem>
         <asp:ListItem>Item 5</asp:ListItem>
         <asp:ListItem>Item 6</asp:ListItem>

      </asp:ListBox>

      <br /><br />

      <asp:button id="Button1"
           Text="Submit" 
           OnClick="SubmitBtn_Click" 
           runat="server" />

      <br /><br />
        
      <asp:Label id="Message" 
           runat="server"/>
        
   </form>

</body>
</html>

<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ListBox Example</title>
<script runat="server">

      Sub SubmitBtn_Click(sender As Object, e As EventArgs) 

         Message.Text = "You chose: <br />"
         
         ' Iterate through the Items collection of the ListBox and 
         ' display the selected items.
         Dim item As ListItem
         For Each item in ListBox1.Items

            If item.Selected Then

               Message.Text &= item.Text & "<br />"

            End If

         Next

      End Sub

   </script>

</head>
<body>

   <h3>ListBox Example</h3>

   <form id="form1" runat="server">

      Select items from the list and click Submit. <br />

      <asp:ListBox id="ListBox1" 
           Rows="6"
           Width="100px"
           SelectionMode="Multiple" 
           runat="server">

         <asp:ListItem Selected="True">Item 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem>
         <asp:ListItem>Item 5</asp:ListItem>
         <asp:ListItem>Item 6</asp:ListItem>

      </asp:ListBox>

      <br /><br />

      <asp:button id="Button1"
           Text="Submit" 
           OnClick="SubmitBtn_Click" 
           runat="server" />

      <br /><br />
        
      <asp:Label id="Message" 
           runat="server"/>
        
   </form>

</body>
</html>

Açıklamalar

Denetimin SelectionMode mod davranışını ListBox belirtmek için özelliğini kullanın. Bu özelliğin ListSelectionMode.Single olarak ayarlanması denetimden ListBox yalnızca tek bir öğenin seçilebileceğini belirtirken ListSelectionMode.Multiple , birden çok öğenin seçilebileceğini belirtir.

özelliğinin SelectionMode değeri görünüm durumunda depolanır.

Şunlara uygulanır

Ayrıca bkz.