473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

combobox, filling textfield

I am filling a combobox with data from a table.
This is done with the code below.
After update of the combobox I want to fill txtField2 with data from Field2
in the select-statement.
How can I do that?

private void Page_Load(object sender, System.EventArgs e)
{
if (! Page.IsPostBack)
{
InitiateInstitution();
}
}
public void InitiateInstitution()
{
connName.Open();
SqlCommand cmd = new SqlCommand("SELECT Field1, Field2, Field3 FROM
tblInstitution ORDER BY Field1", connName);
SqlDataReader dr = cmd.ExecuteReader();
cboInstitution.DataSource = dr;
cboInstitution.DataTextField = "Field1";
cboInstitution.DataBind();
dr.Close();
connName.Close();
}

regards
reidarT
Nov 17 '05 #1
1 1563
One approach might be to set the DataValueField of the combobox to Field2
and then use the SelectedIndexChanged event of the combobox (dropdownlist)
to set the value of txtField2. Of course this would require a postback.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.
"reidarT" <re****@eivon.no> wrote in message
news:#9*************@TK2MSFTNGP09.phx.gbl...
I am filling a combobox with data from a table.
This is done with the code below.
After update of the combobox I want to fill txtField2 with data from Field2
in the select-statement.
How can I do that?

private void Page_Load(object sender, System.EventArgs e)
{
if (! Page.IsPostBack)
{
InitiateInstitution();
}
}
public void InitiateInstitution()
{
connName.Open();
SqlCommand cmd = new SqlCommand("SELECT Field1, Field2, Field3 FROM
tblInstitution ORDER BY Field1", connName);
SqlDataReader dr = cmd.ExecuteReader();
cboInstitution.DataSource = dr;
cboInstitution.DataTextField = "Field1";
cboInstitution.DataBind();
dr.Close();
connName.Close();
}

regards
reidarT

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Maurice Mertens | last post by:
Does anyone know how to get an auto-filling combobox on a form? When I add a combobox to a form I can set the DropDownStyle property to DropDownList. This will make the combobox auto-filling. But...
1
by: zfeld | last post by:
I need an event notification when the user types anything in the combobox textfield? I know about the TextChanged Event but the problem is this is also fired when the user selects an item in the...
0
by: zfeld | last post by:
I have a ComboBox with the Simple DropDownStyle. when I select an item in the combobox list the SelectedIndexChanged Event and the SelectionChangeCommited Event are fired. When I type something...
2
by: Vern | last post by:
I created a table in a dataset that contains multiple columns. I attached a combo box to that table. Now I'm doing something wrong with trying to retrieve the value of the third column of the...
2
by: Tamir Berger | last post by:
Hi, I have an ASP.NET form that includes several combo Boxes. The first Combo is loaded with items on Page_load. The second depends on the item selected on the first, the third on the second...
2
by: jobi | last post by:
Hi, I have this combobox which has a table from a dataset as datasource. When I click an item on the combobox-list , I would like to display (in textfield) the value from an other column that...
6
by: Lars Netzel | last post by:
I have ask this before and I got a link to a solution where you actually show a new from on top of everything with a listbox in, where you can have multicolumns.. and that's what I use now.. That...
6
by: Sakharam Phapale | last post by:
Hi All, How to fill one ComboBox from other ComboBox control? 1) Only setting the reference does the trick but doesn't show items in control. If you see in immediate window, it shows...
4
by: pointies | last post by:
I have a form with a ComboBox with a list of users. The ComboBox is set on a Table/Query to look up the Employee Names by their ID. The ComboBox is named AssignedTo If I set up a Textbox with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.