我的.net环境最近出了一些问题,很多原来正常运行的代码都不正常了,具体请看下面这段代码:
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
OracleConnection strcon=new OracleConnection(连接串);
strcon.Open();
OracleCommand cmd=new OracleCommand("select field1 from testtable",strcon);
this.DropDownList1.DataSource=cmd.ExecuteReader();
this.DropDownList1.DataBind();
strcon.Close();
this.bindtogrid();
this.Label1.Visible=false;
}
}private void bindtogrid()
{
OracleConnection strcon=new OracleConnection(连接串);
strcon.Open();
OracleDataAdapter oda=new OracleDataAdapter();
oda.SelectCommand=new OracleCommand("select * from testtalbe",strcon);
DataSet ds=new DataSet();
oda.Fill(ds,"dzsj");
this.DataGrid1.DataSource=ds.Tables["dzsj"];
this.DataGrid1.DataBind();
strcon.Close();
} private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
this.bindtogrid();
}private void Button1_Click(object sender, System.EventArgs e)
{
   代码略
}我建了几个控件:一个datagrid,一个DropDownList,一个label,一个按钮,datagrid控件设置允许分页,并填写了PageIndexChanged事件的代码,现在让我困惑的是:
1.pageload中设置label1为不可见,可点击按钮后它又出现了;
2.pageload中对DropDownList1绑定了数据,可点击按钮后绑定的数据不见了;
3.点击datagrid1的分页按钮时,datagrid1控件不见了,看来PageIndexChanged中的代码没有执行。
InitializeComponent()中以上事件都正常定义。