Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 24th, 2006, 03:33 PM
Registered User
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multipleslection is not working

Hi all,
I am just wondering why the below code is not working when i make a mulitple selectin from a list box. when i make a single selection it works fine. if you have any idea pls let me know and thanks for your help

<%@ Import namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb"%>

<html>
  <head><title>Multiple Selections</title></head>
  <body>
    <h3>Multiple Selections</h3>
    <form id="Form1" runat="server">
      <asp:listBox id = "lstListBox"
                        selectionmode=Multiple
                        AutoPostBack="false"
                        Runat="server" AppendDataBoundItems="True" >
          <asp:ListItem Value="state">-- State--</asp:ListItem>
      </asp:listBox>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" /><br/><br/>
      <asp:gridview id="gvEmployee" runat="server" >
          <Columns>
              <asp:BoundField />
          </Columns>
      </asp:gridview>
    </form>
  </body>
</html>

<script language="vb" runat="server">

    Dim myConnection As OleDbConnection
    Dim connectionString As String

    Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)

        ' Dim txtstring As String
        ' txtstring = TextBox1.Text
        If Not IsPostBack Then
            connectionString = "provider=MSDAORA;Data Source=xx;User ID=xx;Password=xx;"
            Dim objConnection As New OleDbConnection(connectionString)
            Dim strSQLforListBox As String = "SELECT distinct astate FROM VENDADDR ORDER BY astate"
            objConnection.Open()
            Dim objCommand As New OleDbCommand(strSQLforListBox, objConnection)


            lstListBox.DataSource = objCommand.ExecuteReader()
            lstListBox.DataTextField = "astate"
            lstListBox.DataValueField = "astate"
            lstListBox.DataBind()
            objConnection.Close()
        End If
    End Sub


    Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs)

        ' Remove next line prior to deployment
        ' Response.Write("subListChange triggered")

        Dim strWhereClause As String = ""
        Dim liThisOne As ListItem

        For Each liThisOne In lstListBox.Items
            If liThisOne.Selected Then
                'strWhereClause += "astate=" & liThisOne.Value & " OR "
                strWhereClause += liThisOne.Value & " OR "
            End If

        Next

        ' Remove next line prior to deployment
        ' Response.Write("strWhereClause = <br/>" & strWhereClause & "")

        If strWhereClause.Length > 0 Then
            gvEmployee.Visible = True
            strWhereClause = Left(strWhereClause, strWhereClause.Length - 4)
            'strWhereClause = "WHERE " & strWhereClause
            connectionString = "provider=MSDAORA;Data Source=ss;User ID=ss;Password=ss;"
            Dim strSQLforGrid As String = "SELECT vendor,astate FROM VENDADDR where astate=" & "'" & strWhereClause & "'"
            Dim objConnection As New OleDbConnection(connectionString)
            objConnection.Open()
            Dim objCommand As New OleDbCommand(strSQLforGrid, objConnection)

            ' Remove next line prior to deployment
            ' Response.Write("strSQLforGrid = <br/>" & strSQLforGrid & "")


            gvEmployee.DataSource = objCommand.ExecuteReader()
            gvEmployee.DataBind()
            objConnection.Close()
        Else
            gvEmployee.Visible = False
        End If
    End Sub

</script>


 
Old July 25th, 2006, 12:42 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Where in the code is the problem? What do you expect to happen?


 
Old July 25th, 2006, 03:33 PM
Registered User
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your resposne and I figured it out myself. It was sql problem.thank you
One more thing though,Do you happen to know a simpler way to work with listbox multiple selection in asp.net 2.0 if so please let me know.

 
Old July 25th, 2006, 03:49 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Nope.. you still have to loop though the items to find which ones are selected.






Similar Threads
Thread Thread Starter Forum Replies Last Post
window.opener working .... not working alyeng2000 Javascript How-To 5 January 5th, 2007 08:05 AM
Web.Config..Working or Not Working peace95 ASP.NET 1.0 and 1.1 Basics 1 September 18th, 2006 06:53 AM
Local COM working , but not working at Web Serv nagen111 .NET Web Services 3 February 19th, 2005 04:22 AM
Example not working CKucler BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 3 December 8th, 2004 11:26 AM
Get Working Copy... not working Enkiel Classic ASP Basics 0 April 21st, 2004 01:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.