VS 在这一行给出错误:Label1.Text = DropDownList1.SelectedItem.Text;
错误消息说对象引用未设置为对象的实例。有什么解决办法?
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace Login
{
public partial class ViewCourses : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string loginID = Convert.ToString(Session[0]);
DropDownList1.SelectedValue = loginID;
Label1.Text = DropDownList1.SelectedItem.Text;
}
}
}