473,473 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

asp.net : set value and text to dropDownList - databound

6 New Member
hi all,
i have one form.one drop down and one textbox.
table contains two items code and name.
dropdown bind with name.
if i m select value from dropdown than its related code is display in textbox. how it is possible?

thanks in advance
Jan 29 '08 #1
2 2750
shweta123
692 Recognized Expert Contributor
Hi,

You can do this way :

Expand|Select|Wrap|Line Numbers
  1.  con.ConnectionString = "..."
  2.         con.Open()
  3.         da = New OleDbDataAdapter("Select code,name from tablename", con)
  4.         da.Fill(ds)
  5.         DropDownList1.DataSource = ds
  6.         DropDownList1.DataTextField = "name"
  7.         DropDownList1.DataValueField = "code"
  8.         DropDownList1.DataBind()
  9.         con.Close()
hi all,
i have one form.one drop down and one textbox.
table contains two items code and name.
dropdown bind with name.
if i m select value from dropdown than its related code is display in textbox. how it is possible?

thanks in advance
Jan 29 '08 #2
kunal pawar
297 Contributor
you have to bind drop down table


'Fill DataSet ds then bind dropdown
DropDownList1.DataSource = ds
DropDownList1.DataTextField = "name" ' display as text in drop down
DropDownList1.DataValueField = "code" ' value for respective text
DropDownList1.DataBind()



'To take code value of selected item
'write code on selected INdex changed Event of drop down

DropDownList1.SelectedItem.Text 'for TExt
DropDownList1.SelectedItem.Value 'for Value
Jan 30 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
6
by: Matt | last post by:
I'm not entirely sure how to describe this issue. I have a number of ComboBoxes in my application which have their text properties bound to a field in a data set. The items loaded in the ComboBox...
6
by: Dabbler | last post by:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to an SqlDataSource, then have a value from a boundfield in the row be passed as the keyfield for select where clause. Im...
1
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. ...
3
by: podi | last post by:
Hi, I just wonder if there is a way to set a selected item in dropdown list which items are retreived from database without touching c# code ? I mean, i have in gridview, in edit mode one...
2
by: KerryL | last post by:
How do I update the value of a databound column within my datagrid from within the SelectedIndexChanged event of a dropdownlist, also found within my datagrid? I believe I need to determine the...
3
by: Brian VanDyke | last post by:
I have to display a table with customer data (GridView). However, I want to be able to show DropDownList controls inside one of the columns, not just textbox controls. Is this possible? Is it...
3
by: dizzy77 | last post by:
I have a dropdownlist databound to table column with string values "n" i "y". <asp:DropDownList ID="ddlPrivate" runat="server" SelectedValue='<%# Bind("cPrivate") %>'> ...
6
by: Ahmedhussain | last post by:
Hi there, I m doing work on a gridview and Im getting an error: A potentially dangerous Request.Form value was detected from the client (ctl00$Content$GridView1$ctl03$TextBox1="<span...
5
by: nzkks | last post by:
Hi I am using these: ASP.Net 2.0, VB.Net, Visual Studio 2005, SQL Server 2005, Formview controls In a ASP.Net form I have 20 textboxes and 20 dropdownlists(ddl). All ddl(s) are databound and get...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.