combobox, filling textfield

  • Thread starter Thread starter reidarT
  • Start date Start date
R

reidarT

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
 
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.


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
 
Back
Top