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(); }
不过应该是要加个
if(!(IsPostBack))
{
......
.....
...
}
{
// 网页每次加载时,执行的一些操作
if (!IsPostBack)
{
// 网页第一次加载时执行的操作
}
else
{
// 回送时执行的操作
} // 网页每次加载时执行的操作
}
和IsPostBack没有关系吧??
{
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();
}
{
// 在此处放置用户代码以初始化页面
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{}
}