数据绑定SqlDataSource DropDownList值 [英] Databound SqlDataSource DropDownList Values

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

问题描述

我有两个数据绑定到sqldatasource的下拉列表。当我在第一个ddl中选择一个学校的名字时,我希望第二个只显示与该学校匹配的年份。到目前为止,这是行不通的。有人可以帮助我,因为我觉得我被卡住了。



I have two dropdownlists that are databound to a sqldatasource. When I select a name of a school in the first ddl I would like the second to show only years that matches that school. So far this is not working. Can someone help me because I think I am stuck.

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

推荐答案

1.在DropDownListSchools_SelectedIndexChanged()中调用DropDownListCFY1



2.没有必要DropDownListCFY1 SelectedIndexChanged事件



3.set autopastback = true为DropDownListCFY1



protected void DropDownListSchools_SelectedIndexChanged(object sender,EventArgs e)

{

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

con.Open();



lblINST_ID.Text = DropDownListSchools.SelectedValue;





DropDownListCFY1();



}

protected void DropDownListCFY1()

{

SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings [Pass wordConnectionString] .ConnectionString);

con.Open();

SqlCommand scmd = new SqlCommand(从TableFIN中选择TOTASSETS,TOTLIABILITY INST_ID =+ DropDownListCFY1.SelectedValue .ToString(),con);



SqlDataReader dr = scmd.ExecuteReader();

if(dr.Read())

{

TextBoxTA1.Text = dr [TOTASSETS]。ToString();



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







}

dr.Close();

con.Close();
1.Call the DropDownListCFY1 in DropDownListSchools_SelectedIndexChanged()

2.There is no need for DropDownListCFY1 SelectedIndexChanged event

3.set autopastback=true for DropDownListCFY1

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

lblINST_ID.Text = DropDownListSchools.SelectedValue;


DropDownListCFY1();

}
protected void DropDownListCFY1()
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
con.Open();
SqlCommand scmd = new SqlCommand("Select TOTASSETS, TOTLIABILITY 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();



}
dr.Close();
con.Close();


这篇关于数据绑定SqlDataSource DropDownList值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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