这段代码是从2003转到2005的,我直接在2005中写这段代码没有任何问题,但如果先在2003中写,再转到2005中来就出这个问题。Components.User user = new Components.User();
DataTable dt = user.GetAllUser();
if (dt.Rows.Count > 0)
{
this.ListBox1.DataTextField = "UserName";//未将对象的引用设置到对象的实例
this.ListBox1.DataValueField = "UserId";
this.ListBox1.DataSource = dt;
this.ListBox1.DataBind();
}
DataTable dt = user.GetAllUser();
if (dt.Rows.Count > 0)
{
this.ListBox1.DataTextField = "UserName";//未将对象的引用设置到对象的实例
this.ListBox1.DataValueField = "UserId";
this.ListBox1.DataSource = dt;
this.ListBox1.DataBind();
}
this.ListBox1.DataTextField = "UserName";
this.ListBox1.DataValueField = "UserId";
this.ListBox1.DataBind();
好像顺序错了
Components.User user = new Components.User();
DataTable dt = user.GetAllUser();
------------------------------
this.ListBox1.DataSource = dt;
this.ListBox1.DataBind();
----------------------------
if (dt.Rows.Count > 0)
{
this.ListBox1.DataTextField = "UserName";//未将对象的引用设置到对象的实例
this.ListBox1.DataValueField = "UserId";
this.ListBox1.DataSource = dt;
this.ListBox1.DataBind();
}