Click here to Skip to main content
15,908,020 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello to all. I have a problem with my DDLs. I have a total of 11 of them. The main DDL has school names in them. The others have years in them. Tjhey all are databound and the value is the INST_ID. When I select a school in the main DDL it should populate the other DDL with only the years from that school but I get the years from all the school and I have to count the years from the selection of the school. Next I also have the selection of the year to populate the textboxes that are in the form. That part works so far but when I go to other DDL they all rest back to the first year. Why is that happening and what did I do wrong?


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.Data;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing.Printing;
public partial class SchoolReports : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ButtonPrint.Attributes.Add("onclick", "window.print(); return false");
        
    }
    protected void DropDownListSchools_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open(); 


    }
    protected void DropDownListCFY1_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlCommand scmd = new SqlCommand("Select FINYR, TOTASSETS, TOTLIABILITY, UNRNETASSETS from TableFIN where INST_ID = " + DropDownListCFY1.SelectedValue.ToString(), con);
       
        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA1.Text = dr["TOTASSETS"].ToString();

            TextBoxTL1.Text = dr["TOTLIABILITY"].ToString();

            TextBoxTNA1.Text = dr["UNRNETASSETS"].ToString();

        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListCFY2_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlCommand scmd = new SqlCommand("Select FINYR, TOTASSETS, TOTLIABILITY, UNRNETASSETS from TableFIN where INST_ID = " + DropDownListCFY2.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA2.Text = dr["TOTASSETS"].ToString();

            TextBoxTL2.Text = dr["TOTLIABILITY"].ToString();

            TextBoxTNA2.Text = dr["UNRNETASSETS"].ToString();

        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListCFY3_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlCommand scmd = new SqlCommand("Select FINYR, TOTASSETS, TOTLIABILITY, UNRNETASSETS from TableFIN where INST_ID = " + DropDownListCFY3.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA3.Text = dr["TOTASSETS"].ToString();

            TextBoxTL3.Text = dr["TOTLIABILITY"].ToString();

            TextBoxTNA3.Text = dr["UNRNETASSETS"].ToString();

        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListCFY4_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlCommand scmd = new SqlCommand("Select FINYR, TOTASSETS, TOTLIABILITY, UNRNETASSETS from TableFIN where INST_ID = " + DropDownListCFY4.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA4.Text = dr["TOTASSETS"].ToString();

            TextBoxTL4.Text = dr["TOTLIABILITY"].ToString();

            TextBoxTNA4.Text = dr["UNRNETASSETS"].ToString();

        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListCFY5_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlCommand scmd = new SqlCommand("Select FINYR, TOTASSETS, TOTLIABILITY, UNRNETASSETS from TableFIN where INST_ID = " + DropDownListCFY5.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA5.Text = dr["TOTASSETS"].ToString();

            TextBoxTL5.Text = dr["TOTLIABILITY"].ToString();

            TextBoxTNA5.Text = dr["UNRNETASSETS"].ToString();

        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListFY1_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open(); 
    }
    protected void DropDownListFY2_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open(); 
    }
    protected void DropDownListFY3_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void DropDownListFY4_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open(); 
    }
    protected void DropDownListFY5_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open(); 
    }
}
Posted
Comments
Madhav Hatwalne 3-Sep-13 15:43pm    
where is your aspx code ? have you used update panel ?
Computer Wiz99 3-Sep-13 15:45pm    
Here is my aspx code.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SchoolReports.aspx.cs" Inherits="SchoolReports" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 173px;
height: 137px;
}
.style3
{
width: 585px;
height: 137px;
}
.style4
{
width: 383px;
}
.style5
{
width: 167px;
}
.style6
{
text-align: center;
}
.style8
{
font-size: medium;
color: #FF0000;
}
</style>
<script language="javascript" type="text/javascript">
// <![CDATA[

function Reset1_onclick() {

}

// ]]>
</script>
</head>
<body background="Images/mixed-marble_dArc2008.jpg">
<form id="form1" runat="server">
<div>

<table class="style1">
<tr>
<td class="style4">
<img class="style2" src="Images/buildout_logo.jpg" /></td>
<td>
<img class="style3" src="Images/buildout_header.jpg" /></td>
</tr>
</table>

</div>
<p class="style8">
 </p>
<p class="style8">
Information submitted annually by institution, instructed to be derived
from financial audits.
</p>
<p class="style8">
This information supplements information submitted by the institution.
</p>
<p class="style8">
Audited financial statements should bear more weight than this
self-reported data.
</p>
<p>
 </p>
<table class="style1">
<tr>
<td style="text-align: center">
<asp:DropDownList ID="DropDownListSchools" AppendDataBoundItems="True"
runat="server" Width="300px"
onselectedindexchanged="DropDownListSchools_SelectedIndexChanged"
AutoPostBack="True" DataSourceID="SchoolNames" DataTextField="LongName"
DataValueField="INST_ID">
<asp:ListItem Text="-------Select Institution-------" Selected="True" />

<asp:SqlDataSource ID="SchoolNames" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:PasswordConnectionString %>"
DeleteCommand="DELETE FROM [TableCOCINST] WHERE [INST_ID] = @original_INST_ID AND [FTEYEAR] = @original_FTEYEAR AND (([STAFF] = @original_STAFF) OR ([STAFF] IS NULL AND @original_STAFF IS NULL)) AND (([SORTNAME] = @original_SORTNAME) OR ([SORTNAME] IS NULL AND @original_SORTNAME IS NULL)) AND (([ShortNm] = @original_ShortNm) OR ([ShortNm] IS NULL AND @original_ShortNm IS NULL)) AND (([LongName] = @original_LongName) OR ([LongName] IS NULL AND @original_LongName IS NULL)) AND (([SYSTEM] = @original_SYSTEM) OR ([SYSTEM] IS NULL AND @original_SYSTEM IS NULL)) AND (([ADDR1] = @original_ADDR1) OR ([ADDR1] IS NULL AND @original_ADDR1 IS NULL)) AND (([ADDR2] = @original_ADDR2) OR ([ADDR2] IS NULL AND @original_ADDR2 IS NULL)) AND (([CITY] = @original_CITY) OR ([CITY] IS NULL AND @original_CITY IS NULL)) AND (([STATE] = @original_STATE) OR ([STATE] IS NULL AND @original_STATE IS NULL)) AND (([ZIP] = @original_ZIP) OR ([ZIP] IS NULL AND @original_ZIP IS NULL)) AND (([Country] = @original_Country) OR ([Country] IS NULL AND @original_Country IS NULL)) AND (([Phone]
Nelek 3-Sep-13 16:42pm    
Better use the "improve question" widget and paste the asp code to the original text of the question. You can use the code blocks to improve readability. Here is quite difficult to read.
Madhav Hatwalne 3-Sep-13 15:56pm    
when you select 1 dropdown your all dropdon gets reset this is your original problem ?
Computer Wiz99 3-Sep-13 15:58pm    
This is one of the problems. Yes.

1 solution

Use update panel for drop down list this is happening because when you change the index of the page whole page loaded again to avoid it use update panel
 
Share this answer
 

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