0

我需要根据下拉列表选择的值填充网格:我的 c# 编码是

protected void atddroplist_SelectedIndexChanged(object sender, EventArgs e)
{
      empatdListBI c = new empatdListBI();
      DbConnection b = new DbConnection();
      SqlDataAdapter da = new SqlDataAdapter();
      DataTable dt = new DataTable();
      DataSet ds = new DataSet();


      if (atddroplist.SelectedIndex == 1)
      {
         b.OpenConnection();
         dt = c.LoadRecords(empText.Text);
         GridView1.DataSource = dt;
         GridView1.DataBind();
         b.CloseConnection();
      }
}

使用此编码,我无法在输出中看到 Grid。请帮帮我

4

2 回答 2

0

我们可以检查几件事
- 下拉菜单的 AutoPostBack 设置为 True
- 我们在 dt 中获取数据
- 如有必要,我们可以将网格放在页面的更新面板中

于 2013-07-22T07:45:17.900 回答
0
    if (atddroplist.SelectedIndex  == 1)
            {
              empatdListBI c = new empatdListBI();
      DbConnection b = new DbConnection();
      SqlDataAdapter da = new SqlDataAdapter();
               DataTable DT = new DataTable();
               DT = c.LoadRecords(empText.Text);
  b.OpenConnection();
               if (DT.Rows.Count == 0)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "PopUp", "alert(' Record Not Found...');", true);
                    txtsearchrecord.Text = "";
                    txtsearchrecord.Focus();
                }
                else
                {
                    GridView1.DataSource = DT;
                    GridView1.DataBind();                    
                }  
     b.CloseConnection();                 
            }
于 2013-07-22T12:00:42.770 回答