日期:2014-05-19  浏览次数:20391 次

Session 问题哦 怎么去判断空的数值,,,如果空我做操作,怎么用??
例如
#region   传送数值给   Session
private   void   DataGrid1_UpdateCommand(object   source,   System.Web.UI.WebControls.DataGridCommandEventArgs   e)
{
Session[ "个人ID "]=   e.Item.Cells[1].Text.Trim();
Session[ "人员编码 "]=   e.Item.Cells[2].Text.Trim();
}
#endregion


----------------------
这样判断不行哦     有什么别的方法可以判断空数值吗?
if(Session[ "人员编码 "].ToString()== " ")
{
this.Label1.Text= "前选择你要查看的信息!! ";
}
else
{
                                                                            ...........
                                                                              }

------解决方案--------------------
if(Session[ "人员编码] == null)
{
//为空,转到重新登录页面或者提示错误。
}
------解决方案--------------------
if(Session[ "人员编码 "].ToString()== " ")

----->

if(Session[ "人员编码 "]==null || Session[ "人员编码 "].ToString()== " ")

先判断null再判断内容,否则可能有空引用null reference的错误;
session的key名最好用英文。
------解决方案--------------------
应该前面判断一下
if(Session[ "人员编码 "]!= null) 用中文做变量名不好,改用英文的吧,比如 uid
------解决方案--------------------
if(Session[ "人员编码 "]!= null)
{
this.Label1.Text= "前选择你要查看的信息!! ";
}
else
{
...........
}