Как установить множественные выборы в ASP.NET ListBox?

Number.prototype.padZero= function(len){
 var s= String(this), c= '0';
 len= len || 2;
 while(s.length < len) s= c + s;
 return s;
}

// используется:

(function(){
 var myDate= new Date(), myDateString;
 myDate.setDate(myDate.getDate()+10);

 myDateString= [myDate.getDate().padZero(),
 (myDate.getMonth()+1).padZero(),
 myDate.getFullYear()].join('/');

 alert(myDateString);
})()

/*  value: (String)
09/09/2010
*/
9
задан Tony_Henrich 1 July 2009 в 21:09
поделиться

2 ответа

это код VB для этого ...

myListBox.SelectionMode = Multiple
For each i as listBoxItem in myListBox.Items
  if i.Value = WantedValue Then
      i.Selected = true
  end if 
Next
7
ответ дан 4 December 2019 в 06:49
поделиться

Вот пример C #


(aspx)

<form id="form1" runat="server">
        <asp:ListBox ID="ListBox1" runat="server" >
            <asp:ListItem Value="Red" />
            <asp:ListItem Value="Blue" />
            <asp:ListItem Value="Green" />
        </asp:ListBox>
        <asp:Button ID="Button1" 
                    runat="server" 
                    onclick="Button1_Click" 
                    Text="Select Blue and Green" />
</form>

(Code Behind)

protected void Button1_Click(object sender, EventArgs e)
{
     ListBox1.SelectionMode = ListSelectionMode.Multiple;            
     foreach (ListItem item in ListBox1.Items)
     {
          if (item.Value == "Blue" || item.Value == "Green")
          {
               item.Selected = true;
          }
     }
}
13
ответ дан 4 December 2019 в 06:49
поделиться
Другие вопросы по тегам:

Похожие вопросы: