Re: ListBox will not populate

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Alex Feinman [MVP] (public_news_at_alexfeinman.com)
Date: 01/26/05


Date: Wed, 26 Jan 2005 01:07:08 -0800

Wrong group.
As for you code, remove the following from the Rage directive:

Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="CH5_ListBoxes.WebForm1"

-- 
Alex Feinman
---
Visit http://www.opennetcf.org
"google_me" <ben.ong@natoil.com> wrote in message 
news:1106696867.111790.111360@f14g2000cwb.googlegroups.com...
> Hi,
> I was doing some C#/ASP.NET examples from an O'Reilly book.
>
> I have this sample of code :
> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
> AutoEventWireup="false" Inherits="CH5_ListBoxes.WebForm1" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
> <HTML>
> <HEAD>
> <title>ASP List Box Control</title>
> <script runat="server">
> void Page_Load(Object sender, EventArgs e)
> {
> // Put user code to initialize the page here
> if (!IsPostBack)
> {
> // Build 2 dim array for the lists
> // First dimension contains book name
> // 2nd dimension contains ISBN number
>
> string[,] books = {
> {"Programming C#", "0596001177"},
> {"Programming ASP.NET", "0596001711"},
> {"WebClasses From Scratch", "0789721260"},
> {"Teach Yourself C++", "06723072X"},
> {"Teach Yourself C++ in 10 Minutes", "067231603X"},
> {"XML & Java from Scratch", "0789724766"},
> {"Complete Idiots Guide to a Career in Computer Programming",
> "0789719959"},
> {"XML Web Documents from Scratch", "0789723166"},
> {"Clouds to Code", "1861000952"},
> {"C++: An Introduction to Programming", "1575760614"},
> {"C++ Unleased", "06723122395"}
> };
> // Populate the Lists
> int i;
> for (i=0; i < books.GetLength(0); i++)
> {
> //add both text and value
> lbSingle.Items.Add(new ListItem(books[i,0], books[i,1]));
> lbMulti.Items.Add(new ListItem(books[i,0], books[i,1]));
> }
> }
> }
>
> void lbSingle_SelectedIndexChanged(Object Source, EventArgs E)
> {
> //Check to verify that something has been selected.
> if(lbSingle.SelectedIndex != -1)
> {
> lblLbSingle.Text=lbSingle.SelectedItem.Text + "----> ISBN: " +
> lbSingle.SelectedItem.Value;
> }
> }
> void lbMulti_SelectedIndexChanged(Object Source, EventArgs E)
> {
> string str = "";
> foreach(ListItem li in lbMulti.Items)
> {
> if(li.Selected ==true)
> {
> str += "<br/>" + li.Text + " ----> ISBN: " + li.Value;
> }
> }
> if (str.Length == 0)
> lblLbMulti.Text ="No books selected.";
> else
> lblLbMulti.Text = str;
> }
> </script>
> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE" Content="C#">
> <meta name="vs_defaultClientScript" content="JavaScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> <h1>ASP Controls</h1>
> <h2>List Box</h2>
>
> <h3>ListBox - single selection</h3>
> <asp:ListBox
> id="lbSingle"
> autoPostBack="True"
> rows="6"
> selectionMode="Single"
> onSelectedIndexChanged="lbSingle_SelectedIndexChanged"
> runat="server" />
>
> <br/>
> <asp:Label ID="lblLbSingle" Runat="server" />
> <br/>
>
> <h3>ListBox - multiple selection</h3>
> <asp:ListBox
> id="lbMulti"
> autoPostBack="True"
> selectionMode="Multiple"
> onSelectedIndexChanged="lbMulti_SelectedIndexChanged"
> runat="server" />
> <asp:Label ID="lblLbMulti" Runat="server" />
> </form>
> </body>
> </HTML>
> ... everything compiles but for some reason when the page is brought up
> the list box is not populated with the data found in the "books" array.
> Any help will be great.
>
> Thanks,
>
> Ben
> 


Relevant Pages

  • Re: OOD beginner (i already did a searc of the archives of comp.object)
    ... directory alphabetically lists all names and their phone numbers and ... i struggled for months with Python (i was just beginning programming at ... The first diagram is the OOA/D view where all one needs to know is that the collection is ordered somehow. ... followin boks (listing only those books which are available in INDIA) ...
    (comp.object)
  • Ten all-time most influential math books
    ... books in the world", American Mathematical Monthly ... of Mathematics last term, with rather interesting results. ... To be sure, no two lists will ... influence on the teaching and knowledge of geometry ...
    (sci.math)
  • Re: Ten all-time most influential math books
    ... books in the world", American Mathematical Monthly ... of Mathematics last term, with rather interesting results. ... To be sure, no two lists will ... influence on the teaching and knowledge of geometry ...
    (sci.math)
  • Re: Best writers I havent yet read
    ... Science Fiction> and. ... considered was to look for authors represented by multiple books in my ... So I've spent much of this past week compiling a list of author entries ... If anyone wants the full lists, or whatever, well, e-mail or post, ...
    (rec.arts.sf.written)
  • C++ Cookbook - OReillys Latest Release
    ... difficult languages to learn. ... accomplish common programming tasks in an effective and proven manner. ... 'reference' books. ... XML, using the standard containers, and so on. ...
    (comp.unix.sco.announce)