471,066 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 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 1502
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Maurice Mertens | last post: by
1 post views Thread by zfeld | last post: by
reply views Thread by zfeld | last post: by
2 posts views Thread by Tamir Berger | last post: by
6 posts views Thread by Lars Netzel | last post: by
4 posts views Thread by pointies | last post: by
reply views Thread by leo001 | last post: by

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.