Please Help, How to pass the field value to a text box when drop downlist box item is selected

I am using the following query:

select id, username, company from userinfo order by id.
I am using these two fields id and username for the drop down listbox, which is in the datagrid.

<asp:DropDownList id="name_edit" DataSource="<%# BindTheUserName() %>" OnPreRender="SetDropDownIndex" DataTextField="username" DataValueField="id" runat="server" />
<asp:Textbox runat="server" MaxLength="20" Columns="2" id="txtcompany_edit" Text='<%# trim(DataBinder.Eval(Container.DataItem,"Company")) %>' />

Question: how can i pass the company information to the textbox(txtcompany_edit, which is in the datagrid) when the username is selected from the dropdownlist control.
I have the following code for dropdownlistbox(SetDropDownIndex & BindTheUserName)

Public Function BindTheUserName()
Dim cmdusernames As SqlCommand = New SqlCommand("SELECT id,username,company from userinfo", MyConnection)
cmdusernames.CommandType = CommandType.Text
Return cmdusernames.ExecuteReader(CommandBehavior.CloseConnection)
End Function
Public Sub SetDropDownIndex(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ed As System.Web.UI.WebControls.DropDownList
ed = sender
ed.SelectedIndex = ed.Items.IndexOf(ed.Items.FindByText(strusername))
End Sub

Please help.
Thank you very much.
10/12/2004 5:52:12 PM 91979 articles. 4 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 50

Have you seen this article from 4Guys?

Peter Brunone
Do the impossible, and go home early.
10/15/2004 4:13:40 AM

Similar Artilces:

problem with selected text field and selected value field in check box list
Hi! i have a  problem with check box list:here is the code for binding the check box list with sqldatasource  SqlDataSource1.SelectCommand = "select vcentrolno,inttpaperno from tabmarksdetails where vcbunchno='" & strBunchNo & "'"  chkEnrolNos.DataBind()say now my chkEnrolNos consist of data in this way:vcentrolno        inttpaperno selected text   selected valueA11439            1A11439            2AR439    ...

INSERT INTO statement....getting data from selected value from drop down list and text box.
Bellow is my code...I'm trying to get the value out of the drop down list (ddCategory) and the text box (txtTopic) and place it into the table ChapterDirectivesTopics. Could anyone tell me what i'm doing wrong is telling me the line that has mycommand.ExecuteNonQuery() Is not referenced to an object? I'm not sure what this means and need some help with it. Regards and thanks in advance. Ryan J Boyle Private Sub cmdSubmitTopic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmitTopic.Click ' Needs to be fixed...n...

How to pass java script value to Drop downlist box text in page load event
Hi, <script language="javascript" type="text/javascript">  function GetDate() { var dt=new Date(); document.getElementById('<%=TextBox2.ClientID%>').value = dt.getHours("HH") +":"+ dt.getMinutes("mm"); } </script> from the above java script i want to pass hours value to dropdown listbox text in onload."Getdate()". i created dropdown list box with columns from 1,2,3,4..23 fromf hours selection , but when the form loads i want to show current time hours in dropdownlistbox. i tried like below its...

Populate 2nd drop-down list box based on selected values in 1st drop-down list box
Hi Group,I have two DDL boxes on my page.  DDL one has a list of values and a code.e.g code  ValueABC   123ABC   345FGH   123 DDL 2 should only show values for the code selected in  DDL1 e.g  if user selects record 1 with code ABCthen DDL2 should show ALL records with the linked field value of ABC.The tables are normalized.  For your info, the name of the field of the value I would like to check is called sublistcode.Using  TIA         Try this code: Note: Set appenddataboun...

preset value in text box after selecting a value from a drop down lis (GridView)
Hi, I was wondering if you can help.  I have a gridview control on a page that has a dropdownlist (RoleName) and a text box control (RoleRateValue). The values in the dropdown list are role names and are coming from a database. The text box dispaly nothing. What I want to do is once a users choose a Role (e.g developer) from the drop down list a sql query is triggered through an reader, and I retrieve the Rate of the Role from a database table. I then want to display this value in the text box.  Note my grid consists of ...

how to get the items in a list box when i used jscript to move items from another list box to this list box?
Hello Mate,                   First of all i have 2 list boxes. i am populating the first list box from the database in the load event .and i used jscript to move the items from the first list box to second list box when i click some arrow buttons. now i just want to store the values of the second list box in a datatable and i would like to store that datatable in a session variable.                    If you know any sol...

setting formated value in text box, please help
This is the code for displaying in literal.....  <tr class="dvr"> <td class="dvh"> Trial Period: </td> <td><pre id="trialperioddays"> <asp:Literal ID="TrialPeriodDaysLiteral" Text='<%# SelectedPaymentOption.TrialPeriodDays.ToString("0 days") %>' runat="server" /></pre> </td> </tr>  This is the code for binding in text box var trialPeriodDays = $get('trialperioddays');var trialPeriodDaysTextBox = $get('<%= TrialPeriodDaysT...

get the selected item value of a dropdown box within a gridview
Hello,I have a combobox that is in a column of a grid view. Now it works fine but I now want to update the data source (using sqldatasource update comand) using the value of the selected item in the drop down box. I've tried adding a control parameter but it cant find the control that is within the grid view template. Does anyone know how to do this?thanks Try binding DDL's SelectedValue property (this property doesn't show up on the property window).  For example:    SelectedValue = '<%# Bind("ColumnName") %>' You have to make sure that the underlying column has a valid associated entry in your DDL to avoid an exception....

Pass Values when selecting a GridView to populate text boxes in a FormView -
Any info would be a HUGE Help! thx! I have 1 FormView (insert mode) on a Page, A button within the FormView, that when pressed opens a GridView of Account Details. I need the User to Select one record from Account Details that will Pre-Populate a few fields in the FormView. Then the user can complete the other fields on the form manually, and Insert into the one Master Tble.  My problem is I do not know how to take some values that were selected from the GridView and pre-populate the fields in the FormView before the user Completes and Inserts the FormView.   The ...

can we set value of a text box from selection of items from the listbox by javascript
 Hi all,   How can I set value of a text box from selection of items from the asp listbox or we can use any html control  by javascript, since selectedIndex not working for the list box.. following is the code...<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StateManagement.aspx.cs" Inherits="State_Management" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""><html xmlns="" >&l...

GridView > Text Box Field > Getting the value inside
Hello, What I currently have is a Grid View, which has a few normal bound fields. But there is also one template field - text box. What i'm basically trying to do is, when the user clicks the update button, it retreives the number in the text box, and assigns it to the variable "val". You can ignore the last part as its just a test (basically if it picks the correct value the it will try and take me to Cart.aspx101 for example).I have scoured all corners of the internet looking for a solution. Ive tried all sorts of, e.rowindex, find control, Ctype, selected index etc etc etc...

Load Text box of one web form with selected list item of list box of another web form
one help please Problem is i have two web forms  1.  ForiegnkeyTest.aspx  2. foroginkeytable.aspx   step 1 1 ForiegnkeyTest.aspx one web form <head runat="server"><script language="javascript" type="text/javascript">   function popWin()   {         var confirmWin = null;      confirmWin ='foroginkeytable.aspx','anycontent',   'width=455,height=435,status');   }  </script>     <        &nbsp;<asp:TextBox ID="txtaeropuerto" runat="server" CssClass="txtBox" MaxLength="3" Width="85px"></asp:TextBox></div>        <br />        <br />        <input type="button" onClick="popWin()" value="Open Window">   step2 . foroginkeytable.aspx ( tiena una listbox cargando sobre base de datos <div>        <asp:DropDownList ID="txtciudad" runat="server" CssClass="dropdown" DataSourceID="SqlDataSourceCIUDAD"            DataTextField="CIUDAD" Da...

If user selects item 4 from dynamic drop down, how do I display an additional text box?
I have a dynamic drop down field with data from a sql database.  If the user selects item #4 from the list, I need them to complete the "Details" text box to provide additional information on their answer.  The "Details" text box is ONLY needed if they select item # 4 for now, however I could see it being required for item #5 in the future.    How do I turn "Details" visible if they select #4 from the drop down, but keep it hidden if they select any other option?  My code, all in my .aspx... : <asp:SqlDataSource ...

how to make one list box(this list box should have selected products) gets filled from another list box (for example this list box has the whole products) by using navigation control
Hello Mate!, I have two list boxes. one should get populated with whole products. and i have another list box in which i have to move some of the products which i like .   The design should be the one below: List Box1   List Box 2 all products   Selected products BMW    >> BMW BENZ     > LEXUS AUDI     <   LEXUS    <<     Could you please suggest me whether i have to use buttons(by which i move items from one list box to another)   (>>,>,<,<<) or is there any navigation control to use in Asp.netMuch Obliged & Thanks a Lot,Myself Hi,      refer to the link: I  think this is what you are looking for.. Thanks&Regards, Anil  Thanks to you!Much Obliged & Thanks a Lot,Myself  Thanks to you !.Much Obliged & Thanks a Lot,Myself ...

Get the value of the Text box placed inside a Template Field inside a grid view
Hi All,I need to get the value of the Text box  placed inside a Template Field before the user tries to edit the text box.(I need to get the current value before user enter a new value in the text box)I added a OnFocus attribute on the server side to the textbox and called a function GetCurrentTextBoxValue and I tried using the below in the javascript function but i got an error as undefined.function GetCurrentTextBoxValue { var currentTextBoxValue = document.getElemntById('Rank').Value;}Can anyone help me how to get the text box value inside the template control on an OnFo...

How to add the values of items selected in multi select box
I have several select boxes in which a user is allowed to select more than one item. I am trying to add up the value of the items selected before adding the record to a database. If anyone out there know how I can cycle through the items selected, get the selected value ( a number) of all the items selected and add them together please respond to this message.Thanks Hi,You need to cycle through all item and evaluate the Selected property to know if it is you could doint sum = 0;for (int i = 0; i < ListBox1.Items.Count; i++){    if (ListBox1.Items.Selected)&nbs...

Fetch the value into text box based on the value selected
I have a DataGrid in which it has two DropDowns and two DropDown Have Months like Jan,Feb..... Another is Populated with Years.Based on the month and year selected the TextBoxes have to to be filled with the month Startdate (If is Jan-1/1/YY) and Enddate(1/31/YY).If the month is Feb it has to get only 28 days as Enddate,If it is leap year it has to be filled with MM/29/YY.  Please help, ravi.   There are two options for you, either define a function, that calculates the number of days in that mo...

<Select> drop down box looses its selected value.
Hi..I am using <SELECT> drop down and not ASP drop down ( for some reason)   <select id="locations">                 <optgroup label="Major cities"><option value ="Ahemadabad">Ahemadabad</option><option value ="Bangalore">Bangalore</option></select>  When post back happens, it looses selected value and shows first value ( hence shows Ahemadabad after post back)Please Mark the post as "ANSWER" if it helps yo...

Target Milestone Select box to Text box
Hi All I am new to this bugzilla. In our organization we are using bugzilla version2.18.3 in which, we want a customization. I need to change the "Target Milestone" of show bug page to a text box as currently it shows a select box. How to do this? Is there anyway to change the type of a field? Please help. Thanks & Regards Chandra Shekar P. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around ...

Text box check value from List box.
Hi, I have create asimple function but it is not working correctly. I have 1 textbox, 1 Button, 1 Label and 1 Listbox. I have entered the static name in the listbox. Now I want to check these names through entering names in textbox.protected void btnSubmit_Click(object sender, EventArgs e) {for (int a = 0 ; a < ListBox1.Items.Count ; a++) {if (txtName.Text == ListBox1.Items[a].Text){ lblSubmit.Text = "Your Answer is Correct"; } else {lblSubmit.Text = "Please try again"; }   } } And all the time I found "Please Try again". I want when i e...

cant get text of text box when it dissabled(value changed by javascript)
hi I cant get the text property of texbox properly, if its dissabled. I can get the value if i changed it with server script but i cant get  value when i tried to change the value by client side script(javascript)    this works for me:  <html xmlns=""><head runat="server"> <title></title> <script type="text/javascript">window.onload = function(){ var textbox = document.getElementById('<%= MyTextBox.ClientID %>'); // change value from the textbox ...

Selected Item in Drop Down Box
I am creating a web form where users can edit information that they have entered into a database. It pulls up the record to edit. One of the fields is a drop down box. I have populated the drop down box from a database, but how do I select the item in the drop down that they had previously entered? My code to populate the drop down is below. Thanks for any help you can provide. If Not Page.IsPostBack Then SqlDataAdapter1.Fill(DsEditSchedule1) ddlSection.DataBind() ddlSection.Items.Insert(0, New ListItem("-- Select a Section --", 0)) ...

get value of text box
I new to c# programming. What I have is a webpage with two text boxes and a button When the button is submitted I would like to check the value of of the text boxes in an if statment and compare it to a string. What is the best way to do this. I am using if (txtbox.text ="somevalue") { do something }   I receive Cannot implicitly convert type 'string' to 'bool' when I load the page. any help is appreciated. Hi in C# you check equals with == if (txtbox.text == "somevalue") { do something }Thanks,Teemu KeiskiFinland, EU...

Drop Down Box and Selected Value.
Hello,i have a Dropdown list box on my web form.I have created a Javascipt to prompt an confirmation box to the user when he wants to change to another value of the list.Is there any way i can make the selection return to the original selection (before change) using Javascript??Thank you.- G|oBeMasT - you would have to use the onfocus and set the selectedIndex in a global variable, than you would be able to access the orginal value. | Twitter epascarello | LinkedIn...

Web resources about - Please Help, How to pass the field value to a text box when drop downlist box item is selected -

Ivory Wars: Is it Time for Another Round?
The international ban on trading ivory could soon be lifted, if a new proposal goes through.

Types of MATLAB file extension….a pet name to recognize the file type…
... the extension of .fig by default. (You can specify the format ofimage you would like to store by selecting the format type from the drop downlist ...

Elephant Ivory Sales Denied to Halt Worldwide Poaching Crisis
Environment News Service for the latest environmental news, current issues, climate, water, food, forests, species, energy, education. RSS feed. ...

Smithsonian Conservatory Rescuing Exotic Animals From Extinction
(ABC News) When you see African cheetahs, Chinese red pandas, Micronesian kingfishers and hooded cranes, you might think you’re in the wilds ...

Hunting Report Newsletter For the Hunter Who Travels, by
The Hunting Report - The Newsletter for big game hunters. The Hunting Report covers Africa and hunting in the USA

Catalina Island fox gains numbers. Greatest danger now? People.
... from the list of endangered species. The U.S. Fish and Wildlife Service is considering the proposal as well as a separate plan that would downlist ...

Wolf hunting: 'Every day I feel this weight, this heaviness'
Collette Adkins Giese prepared the lawsuit that sought to stop Minnesota’s new trapping and hunting seasons on wolves.

December 2013 Advances: Additional Resources
Additional resources for Advances articles in the December 2013 issue

Canals and Rivers - UK Canal and River Map - Search -
Map of canals and rivers in the UK provided by Waterscape. Hover over each canal and river on the map to find the waterway of your choice and ...

Feature list : Skin Features - Sokoban Wiki
Feature list : Skin Features From Sokoban Wiki Jump to: navigation , search Contents [ show all ] 1. General Information 1.1 Platforms 1.2 Limits ...

Resources last updated: 3/17/2016 2:44:56 AM