How can I get a drop down list box to populate textboxes in asp.net. I have some code but I am stuck. Please help!!
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Configuration;
public partial class FinanccialIndicatorsForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
SqlCommand scmd = new SqlCommand("Select FINYR from TableFIN where TOTASSETS, TOTLIABILITY and NONEXPPERMRESASSETS = " + DropDownList1.SelectedValue.ToString() + "@TOTASSETS, @TOTLIABILITY and @NONEXPPERMRESASSETS", con);
SqlCommand scmd = new SqlCommand("Select FINYR from TableFIN where TOTASSETS = '" + [add value here] + "' and TOTLIABILITY = '" + [add value here] + "' and NONEXPPERMRESASSETS = '" + [add value here] + "'", con);
try
{
con.Open();
SqlDataReader sdr = scmd.ExecuteReader();
TextBoxLYTA.Text = sdr["TOTASSETS"].ToString();
TextBoxLYTL.Text = sdr["TOTLIABILITY"].ToString();
TextBoxLYNPRNA.Text = sdr["NONEXPPERMRESASSETS"].ToString();
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
}
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
con.Open();
string insCmd = "Insert into TableFIN (TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LOMGTERMDEBT) values (@TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LOMGTERMDEBT)";
SqlCommand insertUser = new SqlCommand(insCmd, con);
insertUser.Parameters.AddWithValue("@TOTASSETS", TextBoxTA.Text);
insertUser.Parameters.AddWithValue("@TOTLIABILITY", TextBoxTL.Text);
insertUser.Parameters.AddWithValue("@NoNEXPPERMRESASSETS", TextBoxNPRNA.Text);
insertUser.Parameters.AddWithValue("@UNRNETASSETS", TextBoxTUNA.Text);
insertUser.Parameters.AddWithValue("@TOTALREV", TextBoxTR.Text);
insertUser.Parameters.AddWithValue("@TUITFEES", TextBoxTFN.Text);
insertUser.Parameters.AddWithValue("@CURRDEBT", TextBoxCD.Text);
insertUser.Parameters.AddWithValue("@LOMGTERMDEBT", TextBoxLTD.Text);
try
{
insertUser.ExecuteNonQuery();
con.Close();
Response.Redirect(".aspx");
}
catch (Exception er)
{
Response.Write("You Have Successfully Submitted the Information!!!");
}
finally
{
}
}
}