0

this is my code...i just try to search the result by the name of school.but the grid view didnt show any thing.my code is

public void gridfill()
{
    markSp spMark = new markSp();
    DataTable dtbl = new DataTable();
    dtbl = spMark.markViewAll();
    gvResult.DataSource = dtbl;
    dtbl = spMark.markViewBySchool(txtSchoolName.Text);
    gvResult.DataSource = dtbl;    
}
protected void Button1_Click(object sender, EventArgs e)
{
    gridfill();
}
public DataTable markViewAll()
{
    DataTable dtbl = new DataTable();
    SqlDataAdapter sqlda = new SqlDataAdapter("markViewAll", sqlcon);
    sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
    sqlda.Fill(dtbl);
    return dtbl;
}
public DataTable markViewBySchool(string viewBySchool)
{
    DataTable dtbClass = new DataTable();
    SqlDataAdapter sqlda = new SqlDataAdapter("markViewBySchool",sqlcon);
    sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
    sqlda.SelectCommand.Parameters.Add("@schoolName", SqlDbType.VarChar).Value = viewBySchool;
    sqlda.Fill(dtbClass);
    return dtbClass;
}
4

3 に答える 3

1

ASP.Net でタグ付けしたので、呼び出す必要があります。DataBind

gvResult.DataBind();

したがって、あなたの方法は次のようになります。

public void gridfill()
{
    markSp spMark = new markSp();
    DataTable dtbl = new DataTable();
    dtbl = spMark.markViewAll(); //you are not using this anywhere
    gvResult.DataSource = dtbl;  // so you can get rid of these two lines
    dtbl = spMark.markViewBySchool(txtSchoolName.Text);
    gvResult.DataSource = dtbl;    
    gvResult.DataBind(); // This is missing
}

次が表示されます: ASP.NET データ バインディングの概要

于 2013-05-06T06:10:26.850 に答える
1
 public void gridfill()
{
      markSp spMark = new markSp();
     DataTable dtbl = new DataTable();
     dtbl = spMark.markViewAll();

     dtbl = spMark.markViewBySchool(txtSchoolName.Text);
     gvResult.DataSource = dtbl; 
     gvResult.Databind(); // You forgot DataBind()  
  }
于 2013-05-06T06:10:31.083 に答える