且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我有2个下拉列表pcode(项目代码)和fyyear(财政年度)我使用数据库编码填充然后在提交按钮我有一个gridview,它将显示与...相关的值

更新时间:2023-10-14 13:08:52

尝试在下拉列表中将autopostback设置为true
Try setting autopostback to true in your dropdownlist


public void Button2_Click(object sender, EventArgs e)
   {
       try
       {


           SqlDataAdapter da = new SqlDataAdapter("select pcode,fyyear,date,salary,ta,contigency,nrc,institcharges,others from monthly where pcode=(''" + DropDownList1.SelectedItem.ToString() + "'' ) AND fyyear=(''" + DropDownList2.SelectedItem.ToString() + "'')", con);
           DataTable dt = new DataTable();
           da.Fill(dt);
           GridView1.DataSource = dt;
           GridView1.DataBind();

           DropDownList1.SelectedIndex = 0;
           DropDownList2.SelectedIndex = 0;
       }

       catch (Exception ex)
       {
           ex.Message.ToString();
       }


   }