multiColumn control passing values to listbox and back

Last post 10-16-2008 2:52 PM by lspence. 3 replies.

Sort Posts:

  • multiColumn control passing values to listbox and back

    10-15-2008, 9:05 AM
    • Member
      90 point Member
    • Spider8990
    • Member since 08-15-2008, 3:08 PM
    • Posts 170

    Hey everyone

    Could someone please help ,I've been looking around on google for 2 days now..and I have no luck...:-(

    I have at this moment 2 listboxes  ...

    User selects keywords from the 1st listbox  ..

    "click add" button ,and the selection value  goes to 2nd listbox...I also have a  "clear all" button function and a "Clear selected" button function...

    That All works fine...but the problem is that  I need the 1st listbox to be multi column......example   

     

    Keyword     |  suggested related Keyword     (two coulmns)

    then add ,clear button functions and a 2nd listbox

     

    Well I've realise that multicolumn is maybe not possible...(well I hope someone can help me...but google is dry on any multicolumn listbox for Asp.net2 web application)

    So the Listview......well I'm running on VWD 2005 .net 2 framework..and there's not one for the web application..(I dont want to use .net 3.5 framework)

    So what else...Gridview to be the substitute for listbox1 ...so Gridview passing values to listbox and back...But I cant get any codes for this to work like listbox to listbox scenario

    to show you what I want please use the following code...(but the first listbox need to be a gridview (or do you have any other ideas of a control) and futher everything needs esle to be the same...functions and the lot

     here' my code for listbox to listbox plus function buttons

     

    Source view 

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
         <asp:listbox id="lstAsset" width="276px" runat=server SelectionMode="Multiple" style="z-index: 100; left: 67px; position: absolute; top: 77px" Height="98px">
                        <asp:listitem>Cat           |see also Animals</asp:listitem>
                        <asp:listitem>Horses    | see also Farm Animal or Animals</asp:listitem>
                        <asp:listitem>Apple      |see also Fruit or Apple trees</asp:listitem>
                        <asp:listitem>Man       |see also Human or Homo Sapien</asp:listitem>
                        <asp:listitem>Surfing     | see also Adventure Sports or Beach activities</asp:listitem>
                                        
                     </asp:listbox>
                 &nbsp; &nbsp;
                     <asp:button ID="Button2" text="Clear Selected" OnClick="RemoveBtn_Click" runat=server Width="94px" style="z-index: 102; left: 368px; position: absolute; top: 121px"/>
                     <asp:button ID="Button3" text="Add Selected" OnClick="AddBtn_Click" runat=server Width="89px" style="z-index: 106; left: 367px; position: absolute; top: 84px"/>
                 &nbsp;
                     <asp:button ID="Button1" text="Clear All" OnClick="RemoveAllBtn_Click" runat=server Width="91px" style="z-index: 104; left: 369px; position: absolute; top: 157px"/>
                   
                     <asp:listbox id="lstSubordinateAsset" width="254px" runat=server SelectionMode="Multiple" style="z-index: 105; left: 69px; position: absolute; top: 213px" Height="104px">
                        
                     </asp:listbox>
                 
        </div>
        </form>
    </body>
    </html>

     code behind vb

     Imports System.Web.UI.HtmlControls
    Imports System.Collections



    Partial Class Default    'change your  page name   
        Inherits System.Web.UI.Page

        Private lasset As New ArrayList()
        Private lsubordinate As New ArrayList()
        Private Shared UpdateList As New ArrayList()

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        End Sub

        Public Sub AddBtn_Click(ByVal Src As [Object], ByVal E As EventArgs)

            If lstAsset.SelectedIndex >= 0 Then
                Dim i As Integer
                For i = 0 To lstAsset.Items.Count - 1
                    If lstAsset.Items(i).Selected Then
                        If Not lasset.Contains(lstAsset.Items(i)) Then
                            lasset.Add(lstAsset.Items(i))
                        End If
                    End If
                Next i


                For i = 0 To lasset.Count - 1
                    If Not lstSubordinateAsset.Items.Contains(CType(lasset(i), ListItem)) Then
                        lstSubordinateAsset.Items.Add(CType(lasset(i), ListItem))
                    End If
                    lstAsset.Items.Remove(CType(lasset(i), ListItem))
                Next i
            End If
        End Sub


        Public Sub RemoveBtn_Click(ByVal Src As [Object], ByVal E As EventArgs)

            If Not (lstSubordinateAsset.SelectedItem Is Nothing) Then

                Dim i As Integer
                For i = 0 To lstSubordinateAsset.Items.Count - 1
                    If lstSubordinateAsset.Items(i).Selected Then
                        If Not lsubordinate.Contains(lstSubordinateAsset.Items(i)) Then
                            lsubordinate.Add(lstSubordinateAsset.Items(i))
                        End If
                    End If
                Next i



                For i = 0 To lsubordinate.Count - 1
                    If Not lstAsset.Items.Contains(CType(lsubordinate(i), ListItem)) Then
                        lstAsset.Items.Add(CType(lsubordinate(i), ListItem))
                    End If
                    lstSubordinateAsset.Items.Remove(CType(lsubordinate(i), ListItem))
                    UpdateList.Add(lsubordinate(i))
                Next i
            End If
        End Sub


        Public Sub RemoveAllBtn_Click(ByVal Src As [Object], ByVal E As EventArgs)

            While lstSubordinateAsset.Items.Count <> 0



                Dim i As Integer
                For i = 0 To lstSubordinateAsset.Items.Count - 1
                    If Not lsubordinate.Contains(lstSubordinateAsset.Items(i)) Then
                        lsubordinate.Add(lstSubordinateAsset.Items(i))
                    End If
                Next i



                For i = 0 To lsubordinate.Count - 1
                    If Not lstAsset.Items.Contains(CType(lsubordinate(i), ListItem)) Then
                        lstAsset.Items.Add(CType(lsubordinate(i), ListItem))
                    End If
                    lstSubordinateAsset.Items.Remove(CType(lsubordinate(i), ListItem))
                    UpdateList.Add(lsubordinate(i))
                Next i
            End While
        End Sub
    End Class


    -------------------------------

    I would apprieciate this so MUCH If someone can give me code that works with a gridview to achive the same result as above... PLEASE!!!!!!!!! PLEASE!!!!

    Thank you so much

    Jake

     

  • Re: multiColumn control passing values to listbox and back

    10-15-2008, 2:31 PM
    Answer
    • Star
      8,817 point Star
    • lspence
    • Member since 11-01-2006, 10:12 AM
    • United States
    • Posts 1,358

    Jake, I put together a sample that you can use as a start. It's in C#, you can use the telerik code converter or any other code converter to convert it to VB.

    http://converter.telerik.com/

    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="BooksGridView" runat="server" CellPadding="4"
    ForeColor="#333333" GridLines="None" AutoGenerateColumns="False"
    onrowcommand="BooksGridView_RowCommand" PageSize="6">
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <RowStyle BackColor="#EFF3FB" />
    <Columns>
    <asp:ButtonField CommandName="Add" Text="Add" />
    <asp:ButtonField CommandName="Remove" Text="Remove" />
    <asp:ButtonField CommandName="RemoveAll" Text="Remove All" />
    <asp:BoundField DataField="Title" HeaderText="Title" />
    <asp:BoundField DataField="Author" HeaderText="Author" />
    <asp:BoundField DataField="Pages" HeaderText="Pages" />
    <asp:BoundField DataField="Publisher" HeaderText="Publisher" />
    </Columns>
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#2461BF" />
    <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
    <br /><br />
    <asp:ListBox ID="BooksListBox" runat="server" BackColor="#CCCCCC"
    Height="150px" Rows="5" Width="800px"></asp:ListBox>
    <br />
    </div>
    </form>
    </body>
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    BooksGridView.DataSource = BookData();
    BooksGridView.DataBind();
    }
    }

    private DataSet BookData()
    {
    DataSet bookDS = new DataSet();
    DataTable bookDT = bookDS.Tables.Add();

    bookDT.Columns.Add("ID", typeof (Int32));
    bookDT.Columns.Add("Title", typeof (string));
    bookDT.Columns.Add("Author", typeof (string));
    bookDT.Columns.Add("Pages", typeof (Int32));
    bookDT.Columns.Add("Publisher", typeof (string));

    bookDT.Rows.Add(1, "Pro ASP.NET 3.5 in C# 2008", "Matthew MacDonald", 1498, "Apress");
    bookDT.Rows.Add(2, "ASP.NET 3.5 Unleashed", "Stephen Walther", 1920, "Sams");
    bookDT.Rows.Add(3, "ASP.NET 3.5 AJAX Unleashed", "Robert Foster", 288, "Sames");
    bookDT.Rows.Add(4, "ASP.NET AJAX in Action", "Alessandro Gallo", 600, "Manning Publications");
    bookDT.Rows.Add(5, "Pro LINQ: Language Integrated Query in C# 2008", "Jr. Jospeh C. Rattz", 600, "Apress");
    bookDT.Rows.Add(6, "Windows Presentation Foundation Unleashed (WPF)", "Adam Nathan", 656, "Sams");
    bookDT.Rows.Add(7, "Learing WCF: A Hands-on Guide", "Michele Bustamante", 607, "O'Reilly Media");
    bookDT.Rows.Add(8, "Pro WF: Windows Workflow in .NET 3.0", "Bruce Bukovics", 744, "Apress");
    bookDT.Rows.Add(9, "XNA 2.0 Game Programming Recipes: A Problem-Solution Approach", "Riemer Grootjans", 648, "Apress");
    bookDT.Rows.Add(10, "XNA GAme Studio Express: Developing Games for Windows and the Xbox 360", "Joseph B. Hall",
    700, "Course Technology");

    return bookDS;
    }

    protected void BooksGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    if (e.CommandName == "Add")
    {
    int idx = Convert.ToInt32(e.CommandArgument);
    GridViewRow row = BooksGridView.Rows[idx];
    row.BackColor = System.Drawing.Color.LemonChiffon;

    ListItem book = new ListItem();
    book.Text = Server.HtmlDecode(row.Cells[3].Text) + " , " +
    Server.HtmlDecode(row.Cells[4].Text) + " , " +
    Server.HtmlDecode(row.Cells[5].Text) + " pages , " +
    Server.HtmlDecode(row.Cells[6].Text);

    if (!BooksListBox.Items.Contains(book))
    {
    BooksListBox.Items.Add((book));
    }
    }
    else if (e.CommandName == "Remove")
    {
    if (e.CommandName == "Remove")
    {
    int idx = Convert.ToInt32(e.CommandArgument);
    GridViewRow row = BooksGridView.Rows[idx];
    row.BackColor = System.Drawing.Color.Empty;

    ListItem book = new ListItem();
    book.Text = Server.HtmlDecode(row.Cells[3].Text) + " , " +
    Server.HtmlDecode(row.Cells[4].Text) + " , " +
    Server.HtmlDecode(row.Cells[5].Text) + " pages , " +
    Server.HtmlDecode(row.Cells[6].Text);

    if (BooksListBox.Items.Contains(book))
    {
    BooksListBox.Items.Remove(book);
    }
    }
    }
    else if (e.CommandName == "RemoveAll")
    {
    if (e.CommandName == "RemoveAll")
    {
    int idx = Convert.ToInt32(e.CommandArgument);

    foreach (GridViewRow row in BooksGridView.Rows)
    {
    row.BackColor = System.Drawing.Color.Empty;
    }

    BooksListBox.Items.Clear();
    }
    }
    }
      
      
    My Blog
    http://Lspence.blogspot.com

    (Please MARK this post as ANSWERED, if you find it helpful)
  • Re: multiColumn control passing values to listbox and back

    10-16-2008, 2:46 PM
    • Member
      90 point Member
    • Spider8990
    • Member since 08-15-2008, 3:08 PM
    • Posts 170

    Hey Ispence Big Smile

    Thank you so much for you help,that sample definately steared me into the right direction how to approach this,it opend my eyes

    I used some of the code and some from other websites and constructed some thing realy neet YesParty!!!

    Thanks again...Big Smile Big SmileBig SmileBig Smile 

    People like YOU makes this world great!

    Regards 

    Jake


  • Re: multiColumn control passing values to listbox and back

    10-16-2008, 2:52 PM
    • Star
      8,817 point Star
    • lspence
    • Member since 11-01-2006, 10:12 AM
    • United States
    • Posts 1,358

    Your welcome and glad I could help out. Big Smile

    My Blog
    http://Lspence.blogspot.com

    (Please MARK this post as ANSWERED, if you find it helpful)
Page 1 of 1 (4 items)