public partial class _Default : System.Web.UI.Page
{
Common com = new Common();
protected void Page_Load(object sender, EventArgs e)
{
if (String.IsNullOrEmpty((String)System.Web.HttpContext.Current.Session["GoodsCity"]))
{
Label3.Text = Session["GoodsCity"].ToString();[b]//使用“new”关键字创建对象实力;在调用方法前通过检查确定对象是否为null
}
DataTable table = com.paihangProduct(Session["GoodsCity"].ToString());
if (table.Rows.Count != 0)
{
DataList1.DataSource = table;
DataList1.DataBind();
}
}
protected void productdel(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "describe")
{
string goodsid = e.CommandArgument.ToString();
Response.Redirect("productdescribe.aspx?GoodsID=" + goodsid);
}
}
}
在网上也搜到解决方法的 可是没用啊 求各位大神帮忙
{
Common com = new Common();
protected void Page_Load(object sender, EventArgs e)
{
if (String.IsNullOrEmpty((String)System.Web.HttpContext.Current.Session["GoodsCity"]))
{
Label3.Text = Session["GoodsCity"].ToString();[b]//使用“new”关键字创建对象实力;在调用方法前通过检查确定对象是否为null
}
DataTable table = com.paihangProduct(Session["GoodsCity"].ToString());
if (table.Rows.Count != 0)
{
DataList1.DataSource = table;
DataList1.DataBind();
}
}
protected void productdel(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "describe")
{
string goodsid = e.CommandArgument.ToString();
Response.Redirect("productdescribe.aspx?GoodsID=" + goodsid);
}
}
}
在网上也搜到解决方法的 可是没用啊 求各位大神帮忙
解决方案 »
- 一个比较难的算法,求大神演绎,最好是C++或者C#语言。
- 用BackgroundWorker做界面绘制的问题(winform)
- C#Generator方法
- 谁知道i=y-x(y2-y1)/(x2-x1)-(y1x2-y2x1)/(x2-x1)是什么公式,干什么用的
- 初学c#,遇到难题!!!请高手赐教!!!!急!
- 非常奇怪的错误,大家帮忙看看了,真不知道是哪问题了.
- 菜鸟问题 求帮助
- 问个小白问题关于APP.CONFIG
- 对于ref类型的参数,该如何写InvokeMember?
- 关于datatable的问题
- vs2005做网站时无法调试,求高手求助:用户代码未处理,(错误地方我标出来的)
- 神啊~~一個邏輯問題 難死我了!
是不是要判断Session对象是不是为空啊
要是这样的话,可以这样
if(Session["GoodsCity"] == null)
{
Label3.Text = Session["GoodsCity"].ToString();[b]//使用“new”关键字创建对象实力;在调用方法前通过检查确定对象是否为null
}这个代码写的就有问题
使用“new”关键字创建对象实例;在调用方法前通过检查确定对象是否为null
不知道怎么修改才对啊
我问题贴出来的代码是百度后修改的
原来的那段代码是没有 if (String.IsNullOrEmpty((String)System.Web.HttpContext.Current.Session["GoodsCity"]))的
是这样的
public partial class _Default : System.Web.UI.Page
{
Common com = new Common();
protected void Page_Load(object sender, EventArgs e)
{
Label3.Text = Session["GoodsCity"].ToString();
DataTable table = com.paihangProduct(Session["GoodsCity"].ToString());
if (table.Rows.Count != 0)
{
DataList1.DataSource = table;
DataList1.DataBind();
}
}
protected void productdel(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "describe")
{
string goodsid = e.CommandArgument.ToString();
Response.Redirect("productdescribe.aspx?GoodsID=" + goodsid);
}
}
}
我问题贴出来的代码是百度后修改的
原来的那段代码是没有 if (String.IsNullOrEmpty((String)System.Web.HttpContext.Current.Session["GoodsCity"]))的
是这样的
public partial class _Default : System.Web.UI.Page
{
Common com = new Common();
protected void Page_Load(object sender, EventArgs e)
{
Label3.Text = Session["GoodsCity"].ToString();
DataTable table = com.paihangProduct(Session["GoodsCity"].ToString());
if (table.Rows.Count != 0)
{
DataList1.DataSource = table;
DataList1.DataBind();
}
}
protected void productdel(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "describe")
{
string goodsid = e.CommandArgument.ToString();
Response.Redirect("productdescribe.aspx?GoodsID=" + goodsid);
}
}
}应该是Session["GoodsCity"]对象为空
楼主是否少打个叹号!
如果值为null不能用String.IsNullOrEmpty判断吧
直接Session["GoodsCity"]!=null就可以了
System.Web.HttpContext.Current.Session["GoodsCity"]))没有对象,也就是没有内容,不能算空
没有内容的对象强制转换到string是错误的