关于GridView分页问题
public partial class hello_Ex09_03 : System.Web.UI.Page{
protected SqlConnection myConnection = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
if (Session.Count == 0)
{
Response.Redirect("Ex09_01.aspx");
}
else if (!IsPostBack)
{
Label1.Text = "热烈欢迎" + Session["username"].ToString();
string strConn = "server=127.0.0.1;uid=sa;pwd=123;database=Aspnet";
myConnection.ConnectionString = strConn;
BindData();
}
}
private void BindData()
{
string selCmd = "select * from Ex09_GuestBook where ParentID=0 order by PostTime desc";
SqlDataAdapter da = new SqlDataAdapter(selCmd, myConnection);
DataSet ds = new DataSet();
da.Fill(ds, "word");
GridView1.DataSource = ds.Tables["word"].DefaultView;
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindData();
}
}
这个程序当点下一页时为什么会出现异常
异常详细信息: System.InvalidOperationException: ConnectionString 属性尚未初始化。
各位请帮忙看一下