在PageLoad里应该可以的。如果不行,先看看用其他事件能否触发?

解决方案 »

  1.   

    是啊!是在PageLoad中啊!
    不过应该是要加个
    if(!(IsPostBack))
    {
    ......
    .....
    ...
    }
      

  2.   

    protected void Page_Load(Object sender, EventArgs e) 

    // 网页每次加载时,执行的一些操作 
    if (!IsPostBack) 

    // 网页第一次加载时执行的操作 

    else 

    // 回送时执行的操作 
    } // 网页每次加载时执行的操作 

    和IsPostBack没有关系吧??
      

  3.   

    where is your aspx code?  no need for an extra tablepublic void Bindgrid()
    {
     string sele1="select * from wbzl";
     sqlConnection1.Open();
     sqlSelectCommand1=new SqlCommand(sele1,sqlConnection1);
     SqlDataReader reader1=sqlSelectCommand1.ExecuteReader();
     DataGrid1.DataSource=reader1;
     DataGrid1.DataBind();
     reader1.Close();
     sqlConnection1.Close();
    }void Page_Load (Object o, EventArgs e)
    {
       if (!IsPostBack)
          Bindgrid();
    }
      

  4.   

    还是不行,不知为什么?我的page_load是这样的:private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    try
    {
    table=new DataTable();
    if(!(IsPostBack))
                                           Bindgrid();
    }
    catch
    {
    }
    try
    {
    col=new DataColumn();
    col.DataType=System.Type.GetType("System.String");
    col.ColumnName="wbbh";
    col.AutoIncrement=false;
    col.Unique=false;
    col.ReadOnly=false;
    table.Columns.Add(col);
    //***************************************************
    col=new DataColumn();
    col.DataType=System.Type.GetType("System.String");
    col.ColumnName="wbmc";
    col.AutoIncrement=false;
    col.Unique=false;
    col.ReadOnly=false;
    table.Columns.Add(col);
    //***************************************************
    col=new DataColumn();
    col.DataType=System.Type.GetType("System.String");
    col.ColumnName="wbhh";
    col.AutoIncrement=false;
    col.Unique=false;
    col.ReadOnly=false;
    table.Columns.Add(col);
    //***************************************************
    col=new DataColumn();
    col.DataType=System.Type.GetType("System.String");
    col.ColumnName="shbw";
    col.AutoIncrement=false;
    col.Unique=false;
    col.ReadOnly=false;
    table.Columns.Add(col);
    //***************************************************
    col=new DataColumn();
    col.DataType=System.Type.GetType("System.String");
    col.ColumnName="bjfs";
    col.AutoIncrement=false;
    col.Unique=false;
    col.ReadOnly=false;
    table.Columns.Add(col);
    //***************************************************
    col=new DataColumn();
    col.DataType=System.Type.GetType("System.String");
    col.ColumnName="hrfs";
    col.AutoIncrement=false;
    col.Unique=false;
    col.ReadOnly=false;
    table.Columns.Add(col);
    //***************************************************
    col=new DataColumn();
    col.DataType=System.Type.GetType("System.String");
    col.ColumnName="ssdw";
    col.AutoIncrement=false;
    col.Unique=false;
    col.ReadOnly=false;
    table.Columns.Add(col);
    //***************************************************
    DataGrid1.DataSource=table;
    DataGrid1.DataBind(); }
    catch{}
    }
      

  5.   

    兄台,你加个断点看是不是所有程序代码都执行完毕,因为while(reader1.Read())这句话可能不成立,函数返回了,数据也就出不来!