日期:2014-05-18 浏览次数:20826 次
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string str=Convert.ToString (Session["UserName"]); DataTable dt = user.GetInformationByName(str); if(dt!=null)//如果不为空则设置 { this.lblpno.Text = dt.Rows[0][0].ToString(); this.lbltruename.Text = dt.Rows[0][1].ToString(); this.lblsex.Text = dt.Rows[0][2].ToString(); this.lbldepartment.Text = dt.Rows[0][3].ToString(); this.lblclassno.Text = dt.Rows[0][4].ToString(); this.txtemail.Text = dt.Rows[0][5].ToString(); this.lblrole1.Text = dt.Rows[0][6].ToString(); } } }
------解决方案--------------------
if (!IsPostBack) { if(Session["UserName"] != null) string str=Convert.ToString (Session["UserName"]); DataTable dt = user.GetInformationByName(str); if(dt != null || dt.Rows.Count > 0) { this.lblpno.Text = (dt.Rows[0][0]!=null?dt.Rows[0][0].ToString():""); this.lbltruename.Text = dt.Rows[0][1]!=null?dt.Rows[0][1].ToString():""); this.lblsex.Text = dt.Rows[0][2]!=null?dt.Rows[0][2].ToString():""); this.lbldepartment.Text = dt.Rows[0][3]!=null?dt.Rows[0][3].ToString():""); this.lblclassno.Text = dt.Rows[0][4]!=null?dt.Rows[0][4].ToString():""); this.txtemail.Text = dt.Rows[0][5]!=null?dt.Ro