Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 24th, 2006, 12:49 AM
Authorized User
 
Join Date: Sep 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default DropDownList-SelectedIndexChange(Plz Help)

i hav' a drpdwnlst and a textbox on my page. there is a table in sql server 2000 tat contains 2 columns, they are an ID column and a NAME column(the ID column is the Primary Key). the drpdwnlst displays the data from the NAME column using SqlDataSource1. the querystring in sqldatasource1 is the select query for the NAME column.
Now wat i want is, when a particular NAME is selected from the drpdwnlst then the ID for tat particular NAME should be dislayed in the textbox control. Can anyone plz share ur knowledge if u know how to achieve this ???

THANX in ADVANCE
__________________
--------------------------------------------------
therez nothin\' as impossible, bcaz the word itself says : \'i\'-\'m\'-\'possible\'
 
Old October 24th, 2006, 09:02 PM
Registered User
 
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have tried to find the response in the whole net!! i wonder if we get the solution. if you do, pls post it okay.

 
Old October 27th, 2006, 02:33 AM
Authorized User
 
Join Date: Sep 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well, i've got it!!!
select both NAME and ID columns in SqlDataSource1,
then set the DataTextField property to the NAME column,
and DataValueField property to ID column.
After that in SelectedIndexChanged Event set the textbox1.text=dropdownlist1.selectedvalue.
also u have to enable the postback of dropdownlist to TRUE
 
Old November 2nd, 2006, 04:40 PM
Registered User
 
Join Date: Oct 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try to move this line below to you Page_Load function:
textbox1.text=dropdownlist1.selectedvalue

 
Old November 3rd, 2006, 05:35 AM
Authorized User
 
Join Date: Sep 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well ndc550,
moving that line to Page_load also works, but i didn't wanted that as i have some text as the first item on drpdwnlst.

--------------------------------------------------
therez nothin' as impossible, bcaz the word itself says : 'i'-'m'-'possible'
 
Old November 3rd, 2006, 10:54 AM
Authorized User
 
Join Date: Nov 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to davidrodrigues40
Default

Do you want this to be performed with a post back or client side?

 
Old November 4th, 2006, 01:13 AM
Authorized User
 
Join Date: Sep 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi david,

well, i have performed this with as post back and all is working fine.
but i feel the client side would be much better as it would save a lot of time.
Is it possible ???
if u know then plz post again.

--------------------------------------------------
therez nothin' as impossible, bcaz the word itself says : 'i'-'m'-'possible'
 
Old November 4th, 2006, 01:17 PM
Authorized User
 
Join Date: Nov 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to davidrodrigues40
Default

If you want to do this on the client side here is the code:

on page load add this code:
DropDownList1.Attributes.Add("onChange", "changeText(this.value,'" & TextBox1.ClientID & "')")

on the page add the following script
<script type="text/javascript">
  function changeText(value,oTextbox){
    document.getElementById(oTextbox).value = value;
  }
</script>

David Rodrigues
"There is no box"
 
Old November 6th, 2006, 01:40 AM
Authorized User
 
Join Date: Sep 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanx

--------------------------------------------------
therez nothin' as impossible, bcaz the word itself says : 'i'-'m'-'possible'





Similar Threads
Thread Thread Starter Forum Replies Last Post
plz.....plz solve out my problem.... kethireddy435 ASP.NET 1.x and 2.0 Application Design 1 October 4th, 2007 12:56 PM
DropDownList-SelectedIndexChange(Plz Help) dagad ASP.NET 2.0 Professional 3 October 27th, 2006 08:13 AM
Plz help me ritesh_ch23 Pro JSP 1 July 18th, 2006 10:46 PM
plz help me kale_tushar C++ Programming 1 February 26th, 2004 01:01 PM
SelectedIndexChange uses ListItem value Randy76 VS.NET 2002/2003 3 September 11th, 2003 09:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.