Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a form I made that has two dropdownlists and some textboxes. When a user logs in and go to the form they will have to select the school they attend and the year. I am trying to get the textboxes to populate when the student selects the school and year but nothing happens. Can someone please show me where my code went wrong?! I need help!!!

C#
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing.Printing;

public partial class FinancialProfileFormA : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
        


        SqlCommand cmd = new SqlCommand ("Insert into TableFIN (TOTAL_REVE, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, SCHOLARSHI, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT) values (@TOTAL_REVE, @INSTRUCTIO, @RESEARCH, @PUBLIC_SER, @ACADEMIC_S, @STUDENT_SE, @INSTITUTIO, @PHYSICAL_P, @SCHOLARSHI, @AUXILIARY_, @HOSPITALS, @INDEPENDEN, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT)",con);
        
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@TOTAL_REVE", TextBoxTROA.Text);
        cmd.Parameters.AddWithValue("@INSTRUCTIO", TextBoxInstr.Text);
        cmd.Parameters.AddWithValue("@RESEARCH", TextBoxRes.Text);
        cmd.Parameters.AddWithValue("@PUBLIC_SER", TextBoxPubS.Text);
        cmd.Parameters.AddWithValue("@ACADEMIC_S", TextBoxAcad.Text);
        cmd.Parameters.AddWithValue("@STUDENT_SE", TextBoxStudS.Text);
        cmd.Parameters.AddWithValue("@INSTITUTIO", TextBoxInstiS.Text);
        cmd.Parameters.AddWithValue("@PHYSICAL_P", TextBoxOperM.Text);
        cmd.Parameters.AddWithValue("@SCHOLARSHI", TextBoxSFEDA.Text);
        cmd.Parameters.AddWithValue("@AUXILIARY_", TextBoxAuxE.Text);
        cmd.Parameters.AddWithValue("@HOSPITALS", TextBoxHosS.Text);
        cmd.Parameters.AddWithValue("@INDEPENDEN", TextBoxIndeO.Text);
        cmd.Parameters.AddWithValue("@OTHEREXP", TextBoxOED.Text);
        cmd.Parameters.AddWithValue("@TOTASSETS", TextBoxTA.Text);
        cmd.Parameters.AddWithValue("@TOTLIABILITY", TextBoxTL.Text);
        cmd.Parameters.AddWithValue("@NoNEXPPERMRESASSETS", TextBoxNPRNA.Text);
        cmd.Parameters.AddWithValue("@UNRNETASSETS", TextBoxTUNA.Text);
        cmd.Parameters.AddWithValue("@TOTALREV", TextBoxTR.Text);
        cmd.Parameters.AddWithValue("@TUITFEES", TextBoxTFN.Text);
        cmd.Parameters.AddWithValue("@CURRDEBT", TextBoxCD.Text);
        cmd.Parameters.AddWithValue("@LONGTERMDEBT", TextBoxLTD.Text);

        con.Open();
        cmd.ExecuteNonQuery();
        }

   public class PCPrint : System.Drawing.Printing.PrintDocument
    {
        
    }

   protected void ButtonPrint_Click(object sender, EventArgs e)
   {
       
   }

   protected void DropDownListSchool_SelectedIndexChanged(object sender, EventArgs e)
   {
       DataTable dt = new DataTable();
       SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
       connection.Open();
       SqlCommand sqlCmd = new SqlCommand("SELECT * from TableFIN WHERE INST_ID = @", connection);
       SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);


       
       sqlDa.Fill(dt);
       if (dt.Rows.Count > 0)
       {
           TextBoxLYTA.Text = dt.Rows[0]["TOTASSETS"].ToString();
           TextBoxLYTL.Text = dt.Rows[0]["TOTLIABILITY"].ToString();
           TextBoxLYNPRNA.Text = dt.Rows[0]["NONEXPPERMRESASSETS"].ToString();

       }
       connection.Close();
   }
   protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {

   }
}
Posted
Updated 31-Jul-13 4:22am
v2
Comments
Marcus_2 31-Jul-13 9:50am    
You'r not doing anything in DropDownListSchool_SelectedIndexChanged and DropDownList1_SelectedIndexChanged... There would be a good place to start with populating the textboxes.
Computer Wiz99 31-Jul-13 9:56am    
Ok. So, the code I wrote should be moved to those fields? Or write another code?
ZurdoDev 31-Jul-13 10:27am    
Put a breakpoint and see what is happening.
Computer Wiz99 31-Jul-13 10:55am    
Ok. I put a breakpoint and nothing happened. No Load error.
ZurdoDev 31-Jul-13 11:20am    
So, what did happen? You have code to put values into your textboxes so what is happening?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900