Newbie help.
am 07.01.2008 21:52:17 von JeremyWoertink
I have a drop down box, and I want to populate a text box based on
what was selected on the drop down. The drop down contains an ID which
is the primary key for a table i'm using. The other column is the
description. So you select the id from the drop down and it populates
the text box with the appropriate description.
I'm new to ASP.NET and i'm using VB. I don't know how to do this. I
know there is an onChange method for the drop down, but then it sends
me to a spot to write some javascript. I know a little javascript, but
I don't know how to go from javascript to VB so I can query the
database again to get that description that has a the same ID as the
ListBox selected text.
Thanks in advance.
~Jeremy
Re: Newbie help.
am 07.01.2008 23:15:00 von Toze
well if you dont have have the description in the client side you don't need
javscript unless you want to use AJAX
so you need a postback to the server
the simplest way
is to enable autopostback in the dropdown
and then catch the event onSelectedIndexChange of the dropdown (server
event) ( if your using vb double click on dropdown to add handler)
query the database and set the textbox text
hope it helps
wrote in message
news:f2b0acf9-6d38-4f52-b5cc-247e89b29226@e23g2000prf.google groups.com...
>I have a drop down box, and I want to populate a text box based on
> what was selected on the drop down. The drop down contains an ID which
> is the primary key for a table i'm using. The other column is the
> description. So you select the id from the drop down and it populates
> the text box with the appropriate description.
>
>
> I'm new to ASP.NET and i'm using VB. I don't know how to do this. I
> know there is an onChange method for the drop down, but then it sends
> me to a spot to write some javascript. I know a little javascript, but
> I don't know how to go from javascript to VB so I can query the
> database again to get that description that has a the same ID as the
> ListBox selected text.
>
> Thanks in advance.
>
>
> ~Jeremy
RE: Newbie help.
am 07.01.2008 23:21:02 von nemtsev
Do you really wanna do it on client side? because it is easy to do in on
server side.
1) check that you dropdownlst has runat="server" attribute
2) add onchange event handler in VS IDE in control properties.
3) set autopostback = true in control properties
right now if u put break point in your .cs onchange menthod it will be hit
each time u change values in drop down list
it means u can put any code there, like extract values from db and fill
other controls with the results
--
WBR, Michael Nemtsev [.NET/C# MVP].
Blog: http://spaces.live.com/laflour
"JeremyWoertink@gmail.com" wrote:
> I have a drop down box, and I want to populate a text box based on
> what was selected on the drop down. The drop down contains an ID which
> is the primary key for a table i'm using. The other column is the
> description. So you select the id from the drop down and it populates
> the text box with the appropriate description.
>
>
> I'm new to ASP.NET and i'm using VB. I don't know how to do this. I
> know there is an onChange method for the drop down, but then it sends
> me to a spot to write some javascript. I know a little javascript, but
> I don't know how to go from javascript to VB so I can query the
> database again to get that description that has a the same ID as the
> ListBox selected text.
>
> Thanks in advance.
>
>
> ~Jeremy
>