日期:2014-05-18  浏览次数:20560 次

请教listbox问题
<%@page language="vb"%>
<script runat="server">
sub sex_name(ob as object,ev as eventargs)
dim i as integer
if sex.selecteditem.text="man" then "如果选择的单选钮为“男”
  for i=0 to baby_name.items.count-1
  if baby_name.items(i).value="w" then "如果是女生姓名那么删除
  ? ???????????????????????
  end if
  next
end if
end sub
</script>
<html>
<body>
<form runat="server">
<asp:radiobuttonlist id="sex" onselectedindexchanged="sex_name" autopostback="true" runat="server">
<asp:listitem>man</asp:listitem>
<asp:listitem>woman</asp:listitem>
</asp:radiobuttonlist>
<p>
<asp:listbox id="baby_name" runat="server">
<asp:listitem value="m">jone</asp:listitem>
<asp:listitem value="w">marry</asp:listitem>
<asp:listitem value="m">jack</asp:listitem>
<asp:listitem value="w">betty</asp:listitem>
<asp:listitem value="m">tonny</asp:listitem>
<asp:listitem value="m">tom</asp:listitem>
<asp:listitem value="w">anna</asp:listitem>
<asp:listitem value="w">honey</asp:listitem>
<asp:listitem value="m">jarry</asp:listitem>
</asp:listbox>
</form>
</body>
</html>  
想实现当用户单击单选按钮时,列表框根据单选按钮的性别选择自动筛选出男生的姓名或女生的姓名。可以实现吧?要怎样实现?

------解决方案--------------------
VB.NET code
 
        Dim va
        va = Me.sex.SelectedValue
        Dim list = Me.DropDownList2.Items
        Dim v As ListItem
        For Each v In list
            If v.Value = va Then
                v.Enabled = True
            Else
                v.Enabled = False
            End If
        Next