assign data to other controls after select value from dropdownlist

Hello, In the webform, there is one dropdownlist and some text boxes. what i want to do is: once i select one of value from the list, for exsample, employee name, then, his profile, like date of birth, address, phone .. will show in other textbox, my question is, which dropdownlist event i should us? how to assign data to the controls? I am new to ASP. Thank for help in advance.
0
Snowingnow
8/29/2005 1:54:21 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

14 Replies
644 Views

Similar Articles

[PageSpeed] 45

You will have to handle SelectedIndexChanged event and do your save there. Just double click on it in your webform and it will create the event.
Sonu Kapoor [MVP]
Feel free to ask me any .NET question | Ajax Data Controls Forum
0
SonuKapoor
8/29/2005 2:12:10 PM
Thank for the reply. my next question is how do i get the data and assign to the other controls for display? Thanks
0
Snowingnow
8/29/2005 2:31:32 PM

 Snowingnow wrote:
Thank for the reply. my next question is how do i get the data and assign to the other controls for display? Thanks


EDIT: uups, I actually misread your question. Below I am showing how to retrive the data and store it.

You can get the values of textboxes via the Text property. Lets say you have a stored procedure which takes two parameters: EmployeID and Name.

CREATE PROCEDURE [dbo].[pr_UpdateEmployee]
 @nID int,
 @Name varchar(50)
AS

UPDATE t
SET
 UserName = @Name
WHERE
 ID = @nID

Now if you want to use that procedure to update your data, then you will have the following code:

Dim conn as new SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) ' Store the connectionstring in the web.config and retrieve it via ConfigurationSettings.AppSettings
Dim strSP as String = "pr_UpdateEmployee"
Dim cmd As New SqlCommand(strSP)
cmd.Parameters.Add("@nID", txbID.Text) ' You probably dont have the ID in textbox !!!
cmd.Parameters.Add("@Name", txbName.Text)
cmd.Connection = myConnection
cmd.Open()
cmd.ExecuteNonQuery() ' run the query and store data
cmd.Connection.Close()


Sonu Kapoor [MVP]
Feel free to ask me any .NET question | Ajax Data Controls Forum
0
SonuKapoor
8/29/2005 2:50:33 PM
Here is how to retrive the data from the dbase and assign it to the controls. 

Dim conn as new SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) ' Store the connectionstring in the web.config and retrieve it via ConfigurationSettings.AppSettings
Dim strSP as String = "pr_GetEmployeeData"
Dim cmd As New SqlCommand(strSP)
cmd.Parameters.Add("@nID", txbID.Text) ' You probably dont have the ID in textbox !!!
cmd.Connection = myConnection
cmd.Open()

' this datatable will store our data, so that we can use that to fill the controls
Dim dt as new datatable
Dim adp as SqlDataAdapter(cmd, strSP)
adp.Fill(dt)
cmd.Connection.Close()

' now check if we have any rows in the table
if dt.rows.count > 0 then
   txbName.Text = dt.Rows(0)("Name")
   '.. do the same for other controls
end if

In this example, I am assuming that you have created a stored procedure (pr_GetEmployeeData) which returns the required column.
Sonu Kapoor [MVP]
Feel free to ask me any .NET question | Ajax Data Controls Forum
0
SonuKapoor
8/29/2005 2:59:13 PM

Thank you so much.

0
Snowingnow
8/29/2005 3:21:55 PM
Hello, i fellow the step, now the problem is the  selectedIndexChanged Event didnt get fired, when i click on the dropdownlist. Anyideal? Thanks

 

0
Snowingnow
8/29/2005 3:33:58 PM
Can you show me your HTML declaration of the dropdownlist and the event?
Sonu Kapoor [MVP]
Feel free to ask me any .NET question | Ajax Data Controls Forum
0
SonuKapoor
8/29/2005 3:57:11 PM
<asp:DropDownList id="DrpTrainer" style="Z-INDEX: 109; LEFT: 80px; POSITION: absolute; TOP: 16px" runat="server" Width="176px" Visible="False" AutoPostBack="True"></asp:DropDownList>

Private Sub DrpTrainer_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DrpTrainer.SelectedIndexChanged

Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("conString"))
Dim strSQL As String = "SELECT * FROM Trainer where Trainer_Code=@Trainer"
Dim trainerCmd As New SqlCommand(strSQL, conn)
Dim paramTrainername As SqlParameter

paramTrainername = New SqlParameter("@Trainer", SqlDbType.Char, 5)
paramTrainername.Value = DrpTrainer.SelectedItem.Value
trainerCmd.Parameters.Add(paramTrainername)
Dim dtTrainer As New DataTable()
Dim adpTrainer As SqlDataAdapter

adpTrainer.Fill(dtTrainer)
trainerCmd.Connection.Close()
txtComment.Value = 1

If  dtTrainer.Rows.Count > 0 Then
txtName.Value = dtTrainer.Rows(1)("Trainer_Code")
lsStatus.SelectedItem.Value = dtTrainer.Rows(2)("Status")
txtComment.Value = dtTrainer.Rows(3)("Comments")
End If

End Sub
Thanks


0
Snowingnow
8/29/2005 4:09:57 PM

Hi

You should put

AutoPostBack="true" in your DropDownList declaration .

0
kaelaa
8/29/2005 4:15:23 PM
Looks good to me, but why do you have the Visible property set to false?
Sonu Kapoor [MVP]
Feel free to ask me any .NET question | Ajax Data Controls Forum
0
SonuKapoor
8/29/2005 4:38:46 PM
Yes, i have  switch set up for changing visible from ture to flase on purpose. Now the pronblem, when i assign dtTrainer.rows(4).value to one of controls, it error out say "System.IndexOutOfRangeException: There is no row at position 4.", the table has five clolumns, any ideal? Thanks
0
Snowingnow
8/29/2005 8:16:30 PM

You are confusing between columns and rows. To get the data from the 5th column - row 1, you would do this:

' The first parameter is for the row and the second for the column.
dt.Rows(0)(5) ' Row = 1; Colum = 5


Sonu Kapoor [MVP]
Feel free to ask me any .NET question | Ajax Data Controls Forum
0
SonuKapoor
8/29/2005 8:24:49 PM
Thank you so much and it works fine. can i ask you one more question, if you dont mind
i have a popup page with calendar control, it works fine but the problem is, the year, it open with cureent year and month. for example i want to select 1990,1,10, i have to go through back to every moth and get back the year of 1990. is ther any way, the canledar has a year option then i can click on for selection rather than by month, THANKS
0
Snowingnow
8/29/2005 9:00:20 PM
I am not aware of such a feature in the calendar control. You cant do that unless you create your own control. 
Sonu Kapoor [MVP]
Feel free to ask me any .NET question | Ajax Data Controls Forum
0
SonuKapoor
8/29/2005 11:09:25 PM
Reply:

Similar Artilces:

which property i use when i need to assign value when i select data from dropdownlist
i have a dropdownlist and has values like countries and textbox, so i need when the user selects country from the dropdownlist to retrieve data from another field called country code and assign to the text box. Hi, For the dropdownlist you can assign datatextfield and datavaluefield dropdownlist.datasource=ds.tables[0] .defaultview; dropdownlist.datatextfiled="countryname"; dropdownlist.datavaluefield="countrycode"; dropdownlist.databind(); in the selec_changed event of dropdownlist assign the datavaluefield to textbox as txt.text=dropdownlist.sel...

how to get selected the value of cascading Ajax dropdownlist extendar control after postback.
how to retain value of dropdown list after postback which is extended by ajax cascading dropdownlist extendar. thanks in advance.     Hi, Can you further elaborate your problem? your retain value is for nxt drop down list? how many drop down list you have? normally what we trying to retrieve value from selected dropdown value is Label1.Text=DropdownList1.selectedValue :) Regards, Hideyoshi, hi,i have 2 Ajax dropdownlist Which is filed through web service. one filter the other.the second dropdown has value <-All->,a,bwhen i select a and cl...

How Select one dropdownlist value using down arrows corresponding other dropdownlist value are select
I am using two dropdownlist box.One is used for country selection. other one is used for state selection.I am using dropdown selectedindexchanged event. when i click country dropdownlist corresponding state is selected in state dropdownlist box. How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.R.Karthikeyan   kartmca: How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.Generally, we don't implmenet...

Dropdownlist selected value passes first value in list no matter what value is selected. why ?
 HI . I have a dropdownlist. Databinds ok but when I must pass a value as a Selected value it always passes the first value in the list even if I select another value. I tried to set the ddl to enableviewstate false but it doesn't change anything. Any ideas ? Code below, thanksLoading the ddl:       productCategories = CatalogAdmin.Admin_Product_Categories_NotIn(productId);        for (int i = 0; i < productCategories.Rows.Count; i++)        {       &...

getting selected data in grid view according to the selected value in drop down
hi! how can i change the grid view data according to the selected value in the drop down list? Make the DataSource the GridView is bound too have a select statement that uses the value of the dropdownlist as a parameter. hth, mcm  Bind your grid in your drop down selectedindexchange and reference the value being selected in your query likeprotected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e){        string val = DropDownList1.SelectedItem.Text;        //Code for populating your grid here like ...

how to get SELECTED VALUE of parent dropdownlist to target dropdownlist using cascading
Hi All, I am using C# , asp.net2.0 , Ajax1.0 i am filling dropdownlist using cascading ajax extender. i taken help of ajax site and build a code to fill the control. my question is how do i get parent selected item value. my web service code to fill target value public CascadingDropDownNameValue[] GetProd(string knownCategoryValues , string category) {StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); //string subgrp ; //int sub1; //if (!kv.ContainsKey("Prod") || !Int32.TryParse(kv["Prod"], out sub1)) //// if (...

how can i Fill the controls on web page by selecting value from dropdownlist control.
  Hi,  Currentlly i am working on a web application where i require to fill the web form with the selected item in a text box. for example i have dropdown control named supplier_name, and i want to fill all the other controls values from database on the form when i select name from that supplier_name box,i.e , if i select name1, then related to that name, its code,address ,city should appear on related text boxes. I have done the same in windows application with c# , but the problem with web application(asp.net) is that, when i select Supplier _ it...

How to assign string value to dropdownlist when selected value field is an int(id of item)
 Hi i have a problem.In one of my application i am maintaining all controlvalues on a page in session using AJAX.i have done it.My page contain two dropdownlist.Data value field of items in dropdownlist is nothing but the idof items,i am retriving an selected item name from database using its id fromdatabase.once i got name the problem is that how can i give selected item of ddlistis the item name. i am triedddlist.SelectedValue=session("name")\\it gives nullddlist.SelectedItem.Text=session("name")\\\it gives object reference not set to instance of object erro...

FileUpload control value gets clear when another control uses Ajax to retrieve data
Hello all, I have a web form.  There is a DropDownList control inside an update panel and the content is updated when a RadioButtonList control fires SelecteIndexChanged.  I also have another control, a FileUpload control.  If you select a file for the file upload control and then change the value RadionButtonList list control, the selected file in the FileUpload control disappears.How do I prevent RadioButtonList from clearing the value of the FileUpload control?Any help will greatly appreciated,  TIA,Dawa Below is the code: 1 <asp:RadioButtonList ID=&quo...

Getting DropDownlist's DataTextValue Selected Value Given the SelectedValue and/or Selected Item
In the vb.net codebehind, I need to extract something from the Text (displayed) value of dropdownlist's selected item and I have  the SelectedValuand and SelectedItem in hand. How can I do this?  FindControl? Item? row?   Thanks. Well, its easier than you might think. SelectedItem has a "text" property. Thats the selected text right there :)  If you need the Text of the selection, then you have to use the SelectedItem.Text property.  If you want the value (not the displayed text) the you can directly use the SelectedValue. dim sText as String = dropdown...

Select dropdownlist control value
Hi, I have created a dropdownlist dynamically and populated it with numbers from 1 to 10. I also have a submit button on my page which when clicked is supposed to get the number I have selected in my dropdownlist. But this does not happen. It keeps returning 1 even if I select 4. I'm guessing whenever the page is loaded the dropdownlist is being created again and hence it selects the first number which is 1. Can anyone tell me how to solve this problem? How do I get the value of the number I have selected from a dropdownlist which is created dynamically? Thanks in advance for ...

Dropdownlist assign selected value
I have a dropdownlist which I populate from a db table and its value is in one column and the display text is in another.  When I run my report I do a join to get the text to display on the page based on the value column.  Here is my query:  SELECT fcomp_assign, (SELECT fcode_cmmt FROM fcode_mstr WHERE fcode_value = fcomp_assign AND fcode_fldname = 'fcomp_assign') AS AssignedTo FROM fcomp_mstr WHERE fcomp_comp_id = 8  This returns what I expect: 6 and Customer Service Problem is I want to populate the list with this query:SELECT fcode_cmmt, fcode...

Getting The Selected Value of a DropDownList
I have a DropDownList that is populated with selections from a database on the page load event. It displays fine with all the correct values, BUT there is a problem when I try to process its data. I eventually reference the DropDownList during a button's server click event. I want to know which value is selected, and I am trying to do so with a call to: DropDownList.SelectedItem.Value; The problem is that such a call is alway referencing the first item of the list, not the one the user selects. What am I doing wrong? In your page load event handler do you put data bind code ins...

Getting Selected Value from DropDownList
Hi All, I'm trying to get a selected value from a dropdownlist after a submit button is pressed but keep getting the following error: Object reference not set to an instance of an object (that old chestnut!) Ok, here is the way my code is set up: I have a control called Attributes (Attributes.ascx and Attributes.ascx.vb) Attributes.ascx Here I have a dropdownlist whose id is "DataDownTest". Attributes.ascx.vb Here I have, amongst other things, this code: Protected WithEvents DropDownTest As System.Web.UI.WebControls.DropDownList Public ReadOnly Proper...

Web resources about - assign data to other controls after select value from dropdownlist - asp.net.getting-started

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 1/6/2016 6:37:29 PM