473,721 Members | 2,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(objec t sender, System.EventArg s e)
{
if (! Page.IsPostBack )
{
InitiateInstitu tion();
}
}
public void InitiateInstitu tion()
{
connName.Open() ;
SqlCommand cmd = new SqlCommand("SEL ECT Field1, Field2, Field3 FROM
tblInstitution ORDER BY Field1", connName);
SqlDataReader dr = cmd.ExecuteRead er();
cboInstitution. DataSource = dr;
cboInstitution. DataTextField = "Field1";
cboInstitution. DataBind();
dr.Close();
connName.Close( );
}

regards
reidarT
Nov 17 '05 #1
1 1577
One approach might be to set the DataValueField of the combobox to Field2
and then use the SelectedIndexCh anged 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.n o> wrote in message
news:#9******** *****@TK2MSFTNG P09.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(objec t sender, System.EventArg s e)
{
if (! Page.IsPostBack )
{
InitiateInstitu tion();
}
}
public void InitiateInstitu tion()
{
connName.Open() ;
SqlCommand cmd = new SqlCommand("SEL ECT Field1, Field2, Field3 FROM
tblInstitution ORDER BY Field1", connName);
SqlDataReader dr = cmd.ExecuteRead er();
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
2375
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 the user then can't enter text in the combobox which isn't in the list. So I have to set the DropDownStyle property to DropDown to enable the user to enter text which isn't in the list. But unfortunately the combobox doesn't auto-fill the text...
1
10398
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 combobox which updates the textfield, and there is no way of knowing what fired the event other then that it came from the combobox. I am guessing the only way to do this would involve the keyup & keydown events. How about if the user pastes...
0
1320
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 into the ComboBox textfield it de-selects the current selection and any subsequent query of the comboBox's SelectedIndex property will reveal an index of -1 (nothing selected). However, there was neither a SelectedIndexChanged Event nor a...
2
11308
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 selecteditem. The datatable row contains the following columns, (ProductCd, Description, ProductType), the displaymember is Description, and the valuemember is ProductCd. I know how to get the values of the displaymember and valuemember, but how...
2
2549
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 and so on. I don't want to transfer all the data needed with the form and also want to avoid page refresh on every item change.
2
1809
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 is present in the table but is not the ID-column that is connected to toe combobox.datavalue. How can I do this ?
6
3207
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 look sokay but it's not a true Combobox... at all.. So my my customer wants to be able to type stuff into the textfield of combobox and then it's preselected in the list... With the solution I got that' simposiible.. since there are no real...
6
7808
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 the item count correctly
4
2353
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 =AssignedTo , it will just display the ID of the Employee. How do I go about so that this box will show the name instead? Thanks in advance
0
9215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9131
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9064
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6669
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4484
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3189
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.