Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: databind to listbox , then submit to page


Message #1 by dont worry <aspmailbox@y...> on Thu, 31 Oct 2002 13:16:46 -0800 (PST)
On page_load my code binds info. from a database table
to a list box with out a problem.
BUT, when I SELECT an option and submit the page one
of the items. 
The following code keeps telling me none was selected.
++++++++++++++++++++++++++++++++++++
if dgResults.SelectedIndex >  - 1 then
  Label1.Text = "Item selected"
&dgResults.SelectedItem.Text
 else
  Label1.Text = "No Item selected"
 end if
++++++++++++++++++++++++++++++
asp:ListBox
   id="dgResults" 
   runat="server"
   Width="100px"
   DataTextField="CatName" 
   DataValueField="CatID" 
   rows="2"
    />
 ++++++++++++++++++++++++++++++++ 

__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/
Message #2 by "Jay Warmack" <jwarmack@w...> on Thu, 31 Oct 2002 13:52:03 -0800
Are you checking Page.IsPostBack in the Page_Load to avoid re-binding the
data to the control on successive postbacks?  If you keep rebinding the data
to the control, the .Net framework will not be able use the ViewState to
determine if an item was selected in the control.

Jay


----- Original Message -----
From: "dont worry" <aspmailbox@y...>
To: "ASP.NET" <aspx@p...>
Sent: Thursday, October 31, 2002 1:16 PM
Subject: [aspx] databind to listbox , then submit to page


> On page_load my code binds info. from a database table
> to a list box with out a problem.
> BUT, when I SELECT an option and submit the page one
> of the items.
> The following code keeps telling me none was selected.
> ++++++++++++++++++++++++++++++++++++
> if dgResults.SelectedIndex >  - 1 then
>   Label1.Text = "Item selected"
> &dgResults.SelectedItem.Text
>  else
>   Label1.Text = "No Item selected"
>  end if
> ++++++++++++++++++++++++++++++
> asp:ListBox
>    id="dgResults"
>    runat="server"
>    Width="100px"
>    DataTextField="CatName"
>    DataValueField="CatID"
>    rows="2"
>     />
>  ++++++++++++++++++++++++++++++++
>
> __________________________________________________
> Do you Yahoo!?
> HotJobs - Search new jobs daily now
> http://hotjobs.yahoo.com/
>
> ---
>
> ASP.NET 1.0 Namespace Reference with C#
> http://www.wrox.com/acon11.asp?ISBN=1861007442
>
> ASP.NET 1.0 Namespace Reference with VB.NET
> http://www.wrox.com/acon11.asp?ISBN=1861007450
>
> These books are a complete reference to the ASP.NET namespaces
> for developers who are already familiar with using ASP.NET.
> There is no trivial introductory material or useless .NET
> hype and the presentation of the namespaces, in an easy-to use
> alphabetical order ensures a user-friendly reference format.
> We provide in-depth coverage of all the major ASP.NET classes,
> giving you those real-world tips that the documentation doesn't
> offer, and demonstrating complex techniques with simple
> examples.
>
> ---
>

Message #3 by dont worry <aspmailbox@y...> on Thu, 31 Oct 2002 14:08:27 -0800 (PST)
So I need to have this for all my pages?

I put  the following.
sub Page_Load
 If Not Page.IsPostBack then
   databind
 end if
end sub

THANK YOU !!!

   

--- Jay Warmack <jwarmack@w...> wrote:
> Are you checking Page.IsPostBack in the Page_Load to
> avoid re-binding the
> data to the control on successive postbacks?  If you
> keep rebinding the data
> to the control, the .Net framework will not be able
> use the ViewState to
> determine if an item was selected in the control.
> 
> Jay
> 
> 
> ----- Original Message -----
> From: "dont worry" <aspmailbox@y...>
> To: "ASP.NET" <aspx@p...>
> Sent: Thursday, October 31, 2002 1:16 PM
> Subject: [aspx] databind to listbox , then submit to
> page
> 
> 
> > On page_load my code binds info. from a database
> table
> > to a list box with out a problem.
> > BUT, when I SELECT an option and submit the page
> one
> > of the items.
> > The following code keeps telling me none was
> selected.
> > ++++++++++++++++++++++++++++++++++++
> > if dgResults.SelectedIndex >  - 1 then
> >   Label1.Text = "Item selected"
> > &dgResults.SelectedItem.Text
> >  else
> >   Label1.Text = "No Item selected"
> >  end if
> > ++++++++++++++++++++++++++++++
> > asp:ListBox
> >    id="dgResults"
> >    runat="server"
> >    Width="100px"
> >    DataTextField="CatName"
> >    DataValueField="CatID"
> >    rows="2"
> >     />
> >  ++++++++++++++++++++++++++++++++
> >
> > __________________________________________________
> > Do you Yahoo!?
> > HotJobs - Search new jobs daily now
> > http://hotjobs.yahoo.com/
> >
> > ---
> >
> > ASP.NET 1.0 Namespace Reference with C#
> > http://www.wrox.com/acon11.asp?ISBN=1861007442
> >
> > ASP.NET 1.0 Namespace Reference with VB.NET
> > http://www.wrox.com/acon11.asp?ISBN=1861007450
> >
> > These books are a complete reference to the
> ASP.NET namespaces
> > for developers who are already familiar with using
> ASP.NET.
> > There is no trivial introductory material or
> useless .NET
> > hype and the presentation of the namespaces, in an
> easy-to use
> > alphabetical order ensures a user-friendly
> reference format.
> > We provide in-depth coverage of all the major
> ASP.NET classes,
> > giving you those real-world tips that the
> documentation doesn't
> > offer, and demonstrating complex techniques with
> simple
> > examples.
> >
> > ---
> >
> 
> 
> ---
> 
> ASP.NET 1.0 Namespace Reference with C#
> http://www.wrox.com/acon11.asp?ISBN=1861007442
> 
> ASP.NET 1.0 Namespace Reference with VB.NET
> http://www.wrox.com/acon11.asp?ISBN=1861007450
> 
> These books are a complete reference to the ASP.NET
> namespaces 
> for developers who are already familiar with using
> ASP.NET. 
> There is no trivial introductory material or useless
> .NET 
> hype and the presentation of the namespaces, in an
> easy-to use 
> alphabetical order ensures a user-friendly reference
> format.
> We provide in-depth coverage of all the major
> ASP.NET classes, 
> giving you those real-world tips that the
> documentation doesn't 
> offer, and demonstrating complex techniques with
> simple 
> examples.  
> 
> ---


__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/
Message #4 by "Jay Warmack" <jwarmack@w...> on Thu, 31 Oct 2002 14:17:31 -0800
Yes, that's correct.  Now if you add a method that handles the
SelectedIndexChanged event for the listbox like:

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

MessageBox("Show Selected Value", ListBox1.SelectedItem.Value)
End Sub

The method will fire when the page is posted back to the server when the
user clicks a different item in the list.

Good Luck,

Jay

----- Original Message -----
From: "dont worry" <aspmailbox@y...>
To: "ASP.NET" <aspx@p...>
Sent: Thursday, October 31, 2002 2:08 PM
Subject: [aspx] Re: databind to listbox , then submit to page


> So I need to have this for all my pages?
>
> I put  the following.
> sub Page_Load
>  If Not Page.IsPostBack then
>    databind
>  end if
> end sub
>
> THANK YOU !!!
>
>
>
> --- Jay Warmack <jwarmack@w...> wrote:
> > Are you checking Page.IsPostBack in the Page_Load to
> > avoid re-binding the
> > data to the control on successive postbacks?  If you
> > keep rebinding the data
> > to the control, the .Net framework will not be able
> > use the ViewState to
> > determine if an item was selected in the control.
> >
> > Jay
> >
> >
> > ----- Original Message -----
> > From: "dont worry" <aspmailbox@y...>
> > To: "ASP.NET" <aspx@p...>
> > Sent: Thursday, October 31, 2002 1:16 PM
> > Subject: [aspx] databind to listbox , then submit to
> > page
> >
> >
> > > On page_load my code binds info. from a database
> > table
> > > to a list box with out a problem.
> > > BUT, when I SELECT an option and submit the page
> > one
> > > of the items.
> > > The following code keeps telling me none was
> > selected.
> > > ++++++++++++++++++++++++++++++++++++
> > > if dgResults.SelectedIndex >  - 1 then
> > >   Label1.Text = "Item selected"
> > > &dgResults.SelectedItem.Text
> > >  else
> > >   Label1.Text = "No Item selected"
> > >  end if
> > > ++++++++++++++++++++++++++++++
> > > asp:ListBox
> > >    id="dgResults"
> > >    runat="server"
> > >    Width="100px"
> > >    DataTextField="CatName"
> > >    DataValueField="CatID"
> > >    rows="2"
> > >     />
> > >  ++++++++++++++++++++++++++++++++
> > >
> > > __________________________________________________
> > > Do you Yahoo!?
> > > HotJobs - Search new jobs daily now
> > > http://hotjobs.yahoo.com/
> > >
> > > ---
> > >
> > > ASP.NET 1.0 Namespace Reference with C#
> > > http://www.wrox.com/acon11.asp?ISBN=1861007442
> > >
> > > ASP.NET 1.0 Namespace Reference with VB.NET
> > > http://www.wrox.com/acon11.asp?ISBN=1861007450
> > >
> > > These books are a complete reference to the
> > ASP.NET namespaces
> > > for developers who are already familiar with using
> > ASP.NET.
> > > There is no trivial introductory material or
> > useless .NET
> > > hype and the presentation of the namespaces, in an
> > easy-to use
> > > alphabetical order ensures a user-friendly
> > reference format.
> > > We provide in-depth coverage of all the major
> > ASP.NET classes,
> > > giving you those real-world tips that the
> > documentation doesn't
> > > offer, and demonstrating complex techniques with
> > simple
> > > examples.
> > >
> > > ---
> > >
> >
> >
> > ---
> >
> > ASP.NET 1.0 Namespace Reference with C#
> > http://www.wrox.com/acon11.asp?ISBN=1861007442
> >
> > ASP.NET 1.0 Namespace Reference with VB.NET
> > http://www.wrox.com/acon11.asp?ISBN=1861007450
> >
> > These books are a complete reference to the ASP.NET
> > namespaces
> > for developers who are already familiar with using
> > ASP.NET.
> > There is no trivial introductory material or useless
> > .NET
> > hype and the presentation of the namespaces, in an
> > easy-to use
> > alphabetical order ensures a user-friendly reference
> > format.
> > We provide in-depth coverage of all the major
> > ASP.NET classes,
> > giving you those real-world tips that the
> > documentation doesn't
> > offer, and demonstrating complex techniques with
> > simple
> > examples.
> >
> > ---
>
>
> __________________________________________________
> Do you Yahoo!?
> HotJobs - Search new jobs daily now
> http://hotjobs.yahoo.com/
>
> ---
>
> ASP.NET 1.0 Namespace Reference with C#
> http://www.wrox.com/acon11.asp?ISBN=1861007442
>
> ASP.NET 1.0 Namespace Reference with VB.NET
> http://www.wrox.com/acon11.asp?ISBN=1861007450
>
> These books are a complete reference to the ASP.NET namespaces
> for developers who are already familiar with using ASP.NET.
> There is no trivial introductory material or useless .NET
> hype and the presentation of the namespaces, in an easy-to use
> alphabetical order ensures a user-friendly reference format.
> We provide in-depth coverage of all the major ASP.NET classes,
> giving you those real-world tips that the documentation doesn't
> offer, and demonstrating complex techniques with simple
> examples.
>
> ---
>


  Return to Index