求帮忙!!Label3.Text = Session["GoodsCity"].ToString();
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);
}
}
}
在网上也搜到解决方法的 可是没用啊 求各位大神帮忙 --------------------编程问答-------------------- 不太明白你的问题是什么 --------------------编程问答-------------------- 确定,这个 Session["GoodsCity"] 有值 --------------------编程问答-------------------- 不太明白楼主的意思。
是不是要判断Session对象是不是为空啊
要是这样的话,可以这样
if(Session["GoodsCity"] == null) --------------------编程问答-------------------- if (String.IsNullOrEmpty((String)System.Web.HttpContext.Current.Session["GoodsCity"]))
{
Label3.Text = Session["GoodsCity"].ToString();[b]//使用“new”关键字创建对象实力;在调用方法前通过检查确定对象是否为null
}
这个代码写的就有问题 --------------------编程问答-------------------- 看错了。。。。。。。。。。 --------------------编程问答-------------------- 程序运行就报错 就是红色字的错误
使用“new”关键字创建对象实例;在调用方法前通过检查确定对象是否为null
不知道怎么修改才对啊 --------------------编程问答--------------------
你单步调试一下,看看是不是Session["GoodsCity"]为null啊
--------------------编程问答--------------------
程序运行就报错 就是红色字的错误
不太明白楼主的意思。
是不是要判断Session对象是不是为空啊
要是这样的话,可以这样
if(Session["GoodsCity"] == null)
使用“new”关键字创建对象实例;在调用方法前通过检查确定对象是否为null
不知道怎么修改才对啊
你单步调试一下,看看是不是Session["GoodsCity"]为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);
}
}
} --------------------编程问答-------------------- 肯定要判断Session["GoodsCity"]是否为null 啊,否则不能使用.tosting 的方法啊 --------------------编程问答--------------------
我问题贴出来的代码是百度后修改的
程序运行就报错 就是红色字的错误
不太明白楼主的意思。
是不是要判断Session对象是不是为空啊
要是这样的话,可以这样
if(Session["GoodsCity"] == null)
使用“new”关键字创建对象实例;在调用方法前通过检查确定对象是否为null
不知道怎么修改才对啊
你单步调试一下,看看是不是Session["GoodsCity"]为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);
}
}
}
应该是Session["GoodsCity"]对象为空 --------------------编程问答-------------------- ,Session["GoodsCity"] 根本就是null嘛,你确定你给Session["GoodsCity"]赋过值?还是说赋值的时候GoodsCity打错了。0.0 --------------------编程问答--------------------
,Session["GoodsCity"] 根本就是null嘛,你确定你给Session["GoodsCity"]赋过值?还是说赋值的时候GoodsCity打错了。0.0
当然,判空也是必须的。 --------------------编程问答-------------------- 没看懂楼主的意思... --------------------编程问答-------------------- if (String.IsNullOrEmpty((String)System.Web.HttpContext.Current.Session["GoodsCity"]))
楼主是否少打个叹号!
如果值为null不能用String.IsNullOrEmpty判断吧
直接Session["GoodsCity"]!=null就可以了 --------------------编程问答-------------------- 把Session["GoodsCity"]!=null判断加在外面 --------------------编程问答-------------------- if (String.IsNullOrEmpty((String)System.Web.HttpContext.Current.Session["GoodsCity"]))
逻辑错误
应该先判断是否为空,再强制转换成string
System.Web.HttpContext.Current.Session["GoodsCity"]))没有对象,也就是没有内容,不能算空
没有内容的对象强制转换到string是错误的
补充:.NET技术 , C#