 |
| 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
|
|
|
|

October 24th, 2006, 12:49 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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\'
|
|

October 24th, 2006, 09:02 PM
|
|
Registered User
|
|
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

October 27th, 2006, 02:33 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 2nd, 2006, 04:40 PM
|
|
Registered User
|
|
Join Date: Oct 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
try to move this line below to you Page_Load function:
textbox1.text=dropdownlist1.selectedvalue
|
|

November 3rd, 2006, 05:35 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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'
|
|

November 3rd, 2006, 10:54 AM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Do you want this to be performed with a post back or client side?
|
|

November 4th, 2006, 01:13 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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'
|
|

November 4th, 2006, 01:17 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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"
|
|

November 6th, 2006, 01:40 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanx
--------------------------------------------------
therez nothin' as impossible, bcaz the word itself says : 'i'-'m'-'possible'
|
|
 |