当前位置: 代码迷 >> ASP.NET >> 为什么小弟我的listbox总也选不中
  详细解决方案

为什么小弟我的listbox总也选不中

热度:1237   发布时间:2013-02-25 00:00:00.0
为什么我的listbox总也选不中
我明明选中了项但ListBox1.Items(l).Selected   依然不等于true
以下是我的代码
<asp:ListBox   ID= "ListBox1 "   runat= "server "   Height= "136px "   Width= "168px "   SelectionMode= "Multiple "> </asp:ListBox>


        Protected   Sub   Page_Load(ByVal   sender   As   Object,   ByVal   e   As   System.EventArgs)   Handles   Me.Load
                Dim   Conn   As   New   SqlConnection
                Dim   Comd   As   SqlCommand
                Dim   strsql   As   String
                Dim   dset   As   New   DataSet
                Dim   obj   As   New   jbfx.pub
                Dim   Dtrd   As   SqlDataReader
                Conn.ConnectionString   =   obj.Conn_str
                Conn.Open()
                strsql   =   "select   *   from   bm   where   s_sjbm= '00000000 ' "
                Comd   =   New   SqlCommand(Trim(strsql),   Conn)
                Dtrd   =   Comd.ExecuteReader()
                ListBox1.Items.Clear()
                Do   While   Dtrd.Read
                        ListBox1.Items.Add(New   ListItem(Dtrd( "s_bm "),   Dtrd( "s_bmid ")))
                Loop
                Conn.Close()
        End   Sub


        Protected   Sub   Button1_Click(ByVal   sender   As   Object,   ByVal   e   As   System.EventArgs)   Handles   Button1.Click
dim   l   as   integer
                        For   l   =   0   To   ListBox1.Items.Count   -   1
                                If   ListBox1.Items(l).Selected   =   True   Then
                                        Response.Write( " <script> alert( '选中了 ') </script> ")
                                End   If
                        Next
                Conn.Close()
        End   Sub

------解决方案--------------------------------------------------------
在pageload里
加上

if not page.ispostback then
...
end if
------解决方案--------------------------------------------------------
  相关解决方案