Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: listbox server controls and listitem


Message #1 by "Ben Sanchez" <eljami@h...> on Tue, 30 Jul 2002 20:54:47 -0700
Hello List!
 
I was doing one of the Try it Out examples on CH 3 page 110 from the book beginning asp.net 1.0 with c#  but I can't make it work. I
downloaded the code from wrox but it still will not work.
 
it supposed to display the selected item on a label but it does not...
 
anybody know what is the problem?Thanks,
 
Ben
<script runat="server" language="C#">  void Page_Load(){  string msg = "You have selected: <br />";
   if (list1.Items[0].Selected) {
  msg = msg + list1.Items[0].Text + "<br />";}   if (list1.Items[1].Selected) {  msg=msg + list1.Items[1].Text + "<br
/>";}   if (list1.Items[2].Selected){  msg=msg + list1.Items[2].Text + "<br />";}   Message.Text=msg; 
}</script><html>  <head>     <title> Drop Down List Example</title>  </head>  <body>    
<asp:label id="Message" runat="server" />     <br />     <form runat="server">     Which city do you wish to look
at hotels for?<br /><br />     <asp:listbox id="list1" runat="server" selectionmode="multiple">        
<asp:ListItem>Madrid</asp:ListItem>         <asp:ListItem>Oslo</asp:ListItem>        
<asp:ListItem>Lisbon</asp:ListItem>     </asp:listbox>     <br /><br /><br /><br />    
<input type="Submit">      </form></body></html>Send and receive Hotmail on your mobile device: Click Here
Message #2 by "Ben Sanchez" <eljami@h...> on Wed, 31 Jul 2002 05:06:00
Hello List!

I was doing one of the Try it Out examples on CH 3 page 110 from the book 
beginning asp.net 1.0 with c#  but I can't make it work. I downloaded the 
code from wrox but it still will not work.

it supposed to display the selected item on a label but it does not...

anybody know what is the problem?

Thanks,

Ben
<script runat="server" language="C#">
  void Page_Load()
{
  string msg = "You have selected: <br />";
   if (list1.Items[0].Selected) {
  msg = msg + list1.Items[0].Text + "<br />";
}
   if (list1.Items[1].Selected) {
  msg=msg + list1.Items[1].Text + "<br />";
}
   if (list1.Items[2].Selected){
  msg=msg + list1.Items[2].Text + "<br />";
}
   Message.Text=msg;
  }
</script>
<html>
  <head>
     <title> Drop Down List Example</title>
  </head>
  <body>
     <asp:label id="Message" runat="server" />
     <br />
     <form runat="server">
     Which city do you wish to look at hotels for?<br /><br />
     <asp:listbox id="list1" runat="server" selectionmode="multiple">
         <asp:ListItem>Madrid</asp:ListItem>
         <asp:ListItem>Oslo</asp:ListItem>
         <asp:ListItem>Lisbon</asp:ListItem>
     </asp:listbox>
     <br /><br /><br /><br />
     <input type="Submit"> 
     </form>
</body>
</html>
Message #3 by Elissa Setarehshenas <elissasetareh@y...> on Wed, 31 Jul 2002 05:27:04 -0700 (PDT)
Ben,
The book is wrong Page_Load must have the following 2
arguments

void Page_Load(Object sender, EventArgs e)
Once you put that in the code will work.

Elissa


--- Ben Sanchez <eljami@h...> wrote:
> Hello List!
> 
> I was doing one of the Try it Out examples on CH 3
> page 110 from the book 
> beginning asp.net 1.0 with c#  but I can't make it
> work. I downloaded the 
> code from wrox but it still will not work.
> 
> it supposed to display the selected item on a label
> but it does not...
> 
> anybody know what is the problem?
> 
> Thanks,
> 
> Ben
> <script runat="server" language="C#">
>   void Page_Load()
> {
>   string msg = "You have selected: <br />";
>    if (list1.Items[0].Selected) {
>   msg = msg + list1.Items[0].Text + "<br />";
> }
>    if (list1.Items[1].Selected) {
>   msg=msg + list1.Items[1].Text + "<br />";
> }
>    if (list1.Items[2].Selected){
>   msg=msg + list1.Items[2].Text + "<br />";
> }
>    Message.Text=msg;
>   }
> </script>
> <html>
>   <head>
>      <title> Drop Down List Example</title>
>   </head>
>   <body>
>      <asp:label id="Message" runat="server" />
>      <br />
>      <form runat="server">
>      Which city do you wish to look at hotels
> for?<br /><br />
>      <asp:listbox id="list1" runat="server"
> selectionmode="multiple">
>          <asp:ListItem>Madrid</asp:ListItem>
>          <asp:ListItem>Oslo</asp:ListItem>
>          <asp:ListItem>Lisbon</asp:ListItem>
>      </asp:listbox>
>      <br /><br /><br /><br />
>      <input type="Submit"> 
>      </form>
> </body>
> </html>


__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

  Return to Index