DropDownList刷新页面 [英] DropDownList Refresh Page

查看:83
本文介绍了DropDownList刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次用户从下拉列表中选择某些内容时,我是否有办法停止刷新网页?我有11个下拉列表,每个都有不同的功能。这是我的代码。



Is there a way for me to stop the web page from refreshing every time a user selects something from the dropdownlist? I have 11 dropdownlist and every one has a different function. Here is my code.

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");
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
    }
    protected void DropDownListSchools_SelectedIndexChanged(object sender, EventArgs e)
    {
        

        lblINST_ID.Text = DropDownListSchools.SelectedValue;
        

    }
    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 INST_ID, TOTASSETS, TOTLIABILITY, UNRNETASSETS, NonExppermresAssets, TotalRev, TuitFees, CurrDebt, LongTermDebt from TableFIN2009 where INST_ID = " + DropDownListCFY1.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA1.Text = dr["TOTASSETS"].ToString();
            TextBoxTL1.Text = dr["TOTLIABILITY"].ToString();
            TextBoxUNA1.Text = dr["UNRNETASSETS"].ToString();
            TextBoxPRNA1.Text = dr["NonExppermresAssets"].ToString();
            TextBoxTR1.Text = dr["TotalRev"].ToString();
            TextBoxTFN1.Text = dr["TuitFees"].ToString();
            TextBoxCD1.Text = dr["CurrDebt"].ToString();
            TextBoxLDT1.Text = dr["LongTermDebt"].ToString();
            
            int a = Convert.ToInt32(TextBoxTA1.Text);
            int b = Convert.ToInt32(TextBoxTL1.Text);
            TextBoxTNA1.Text = Convert.ToString(a - b);

            int a1 = Convert.ToInt32(TextBoxUNA1.Text);
            int b1 = Convert.ToInt32(TextBoxPRNA1.Text);
            TextBoxTNAS1.Text = Convert.ToString(a1 + b1); 



        }
        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 INST_ID, TOTASSETS, TOTLIABILITY, UNRNETASSETS, NonExppermresAssets, TotalRev, TuitFees, CurrDebt, LongTermDebt from TableFIN2010 where INST_ID = " + DropDownListCFY2.SelectedValue.ToString(), con);
        
        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA2.Text = dr["TOTASSETS"].ToString();
            TextBoxTL2.Text = dr["TOTLIABILITY"].ToString();
            TextBoxUNA2.Text = dr["UNRNETASSETS"].ToString();
            TextBoxPRNA2.Text = dr["NonExppermresAssets"].ToString();
            TextBoxTR2.Text = dr["TotalRev"].ToString();
            TextBoxTFN2.Text = dr["TuitFees"].ToString();
            TextBoxCD2.Text = dr["CurrDebt"].ToString();
            TextBoxLTD2.Text = dr["LongTermDebt"].ToString();

            int a = Convert.ToInt32(TextBoxTA2.Text);
            int b = Convert.ToInt32(TextBoxTL2.Text);
            TextBoxTNA2.Text = Convert.ToString(a - b);

            int a2 = Convert.ToInt32(TextBoxUNA2.Text);
            int b2 = Convert.ToInt32(TextBoxPRNA2.Text);
            TextBoxTNAS2.Text = Convert.ToString(a2 + b2); 

        }
        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 INST_ID, TOTASSETS, TOTLIABILITY, UNRNETASSETS, NonExppermresAssets, TotalRev, TuitFees, CurrDebt, LongTermDebt from TableFIN2011 where INST_ID = " + DropDownListCFY3.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA3.Text = dr["TOTASSETS"].ToString();
            TextBoxTL3.Text = dr["TOTLIABILITY"].ToString();
            TextBoxUNA3.Text = dr["UNRNETASSETS"].ToString();
            TextBoxPRNA3.Text = dr["NonExppermresAssets"].ToString();
            TextBoxTR3.Text = dr["TotalRev"].ToString();
            TextBoxTFN3.Text = dr["TuitFees"].ToString();
            TextBoxCD3.Text = dr["CurrDebt"].ToString();
            TextBoxLTD3.Text = dr["LongTermDebt"].ToString();

            int a = Convert.ToInt32(TextBoxTA3.Text);
            int b = Convert.ToInt32(TextBoxTL3.Text);
            TextBoxTNA3.Text = Convert.ToString(a - b);

            int a3 = Convert.ToInt32(TextBoxUNA3.Text);
            int b3 = Convert.ToInt32(TextBoxPRNA3.Text);
            TextBoxTNAS3.Text = Convert.ToString(a3 + b3); 

        }
        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 INST_ID, TOTASSETS, TOTLIABILITY, UNRNETASSETS, NonExppermresAssets, TotalRev, TuitFees, CurrDebt, LongTermDebt from TableFIN2012 where INST_ID = " + DropDownListCFY4.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA4.Text = dr["TOTASSETS"].ToString();
            TextBoxTL4.Text = dr["TOTLIABILITY"].ToString();
            TextBoxUNA4.Text = dr["UNRNETASSETS"].ToString();
            TextBoxPRNA4.Text = dr["NonExppermresAssets"].ToString();
            TextBoxTR4.Text = dr["TotalRev"].ToString();
            TextBoxTFN4.Text = dr["TuitFees"].ToString();
            TextBoxCD4.Text = dr["CurrDebt"].ToString();
            TextBoxLTD4.Text = dr["LongTermDebt"].ToString();

            int a = Convert.ToInt32(TextBoxTA4.Text);
            int b = Convert.ToInt32(TextBoxTL4.Text);
            TextBoxTNA4.Text = Convert.ToString(a - b);

            int a4 = Convert.ToInt32(TextBoxUNA4.Text);
            int b4 = Convert.ToInt32(TextBoxPRNA4.Text);
            TextBoxTNAS4.Text = Convert.ToString(a4 + b4); 

        }
        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 INST_ID, TOTASSETS, TOTLIABILITY, UNRNETASSETS, NonExppermresAssets, TotalRev, TuitFees, CurrDebt, LongTermDebt from TableFIN2013 where INST_ID = " + DropDownListCFY5.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxTA5.Text = dr["TOTASSETS"].ToString();
            TextBoxTL5.Text = dr["TOTLIABILITY"].ToString();
            TextBoxUNA5.Text = dr["UNRNETASSETS"].ToString();           
            TextBoxPRNA5.Text = dr["NonExppermresAssets"].ToString();
            TextBoxTR5.Text = dr["TotalRev"].ToString();
            TextBoxTFN5.Text = dr["TuitFees"].ToString();
            TextBoxCD5.Text = dr["CurrDebt"].ToString();
            TextBoxLTD5.Text = dr["LongTermDebt"].ToString();

            int a = Convert.ToInt32(TextBoxTA5.Text);
            int b = Convert.ToInt32(TextBoxTL5.Text);
            TextBoxTNA5.Text = Convert.ToString(a - b);

            int a5 = Convert.ToInt32(TextBoxUNA5.Text);
            int b5 = Convert.ToInt32(TextBoxPRNA5.Text);
            TextBoxTNAS5.Text = Convert.ToString(a5 + b5); 

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

        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTAL_FTE from TableFTE2009 where INST_ID = " + DropDownListFY1.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
          TextBoxEPCOC1.Text = dr["TOTAL_FTE"].ToString();
        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListFY2_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();

        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTAL_FTE from TableFTE2010 where INST_ID = " + DropDownListFY2.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxEPCOC2.Text = dr["TOTAL_FTE"].ToString();
        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListFY3_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();

        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTAL_FTE from TableFTE2011 where INST_ID = " + DropDownListFY3.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxEPCOC3.Text = dr["TOTAL_FTE"].ToString();
        }
        dr.Close();
        con.Close();

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

        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTAL_FTE from TableFTE2012 where INST_ID = " + DropDownListFY4.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxEPCOC4.Text = dr["TOTAL_FTE"].ToString();
        }
        dr.Close();
        con.Close();
    }
    protected void DropDownListFY5_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();

        SqlCommand scmd = new SqlCommand("Select INST_ID, TOTAL_FTE from TableFTE2013 where INST_ID = " + DropDownListFY5.SelectedValue.ToString(), con);

        SqlDataReader dr = scmd.ExecuteReader();
        if (dr.Read())
        {
            TextBoxEPCOC5.Text = dr["TOTAL_FTE"].ToString();
        }
        dr.Close();
        con.Close();
    }
    
}

推荐答案

为DropDownList设置Autopostback为false,因此您必须刷新客户端上的数据。



客户端上的下拉列表有一个onchange事件,你可以从那开始。您可以使用updatepanel刷新,也可以查找ajax工具包或jquery插件来解决问题。
Set Autopostback to false for the DropDownList so you have to refresh the data on clientside.

There is an onchange event for dropdownlist on clientside you can start with that. You can use updatepanel to refresh or you can look for ajax toolkit or jquery plugin to solve your problem.


将autopostback属性设置为下拉列表的false。
Set the autopostback property to false of the dropdownlist.


这篇关于DropDownList刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆