| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6135 人关注过本帖
标题:未将对象引用设置到对象实例问题
只看楼主 加入收藏
tremere
Rank: 6Rank: 6
来 自:火星
等 级:侠之大者
帖 子:223
专家分:432
注 册:2013-3-11
结帖率:70.59%
收藏
已结贴  问题点数:20 回复次数:3 
未将对象引用设置到对象实例问题
在前台页面我放了imagebutton
                           
<asp:ImageButton ID="ImageButton2" runat="server"   CommandName="detailSee"  CommandArgument =<%#DataBinder.Eval(Container.DataItem,"BookID") %>
  ImageUrl='<%#DataBinder.Eval(Container.DataItem,"BookUrl") %>'Width="100%"

 onclick="ImageButton2_Click"  />
通过CommandArgument =<%#DataBinder.Eval(Container.DataItem,"BookID") %>绑定数据库的商品id
我想通过这个图片按钮查看商品的详细信息。
程序代码:
    public void GetGoodsInfo()
    {
        string strSql = "select * from tb_BookInfo where BookID=" + Convert.ToInt32(Request["id"].Trim());//断点调试这里的值是null 没获取到商品的id
        SqlCommand myCmd = dbObj.GetCommandStr(strSql);
        DataTable dsTable = dbObj.GetDataSetStr(strSql, "tbBI");
        this.txtCategory.Text = gcObj.GetClass(Convert.ToInt32(dsTable.Rows[0]["ClassID"].ToString()));
        this.txtName.Text = dsTable.Rows[0]["BookName"].ToString();
        this.txtAuthor.Text = dsTable.Rows[0]["Author"].ToString();
        this.txtCompany.Text = dsTable.Rows[0]["Company"].ToString();
        this.txtMarketPrice.Text = dsTable.Rows[0]["MarketPrice"].ToString();
        this.txtHotPrice.Text = dsTable.Rows[0]["HotPrice"].ToString();
        this.ImageMapPhoto.ImageUrl = dsTable.Rows[0]["BookUrl"].ToString();
        this.cbxCommend.Checked = bool.Parse(dsTable.Rows[0]["Isrefinement"].ToString());
        this.cbxHot.Checked = bool.Parse(dsTable.Rows[0]["IsHot"].ToString());
        this.cbxDiscount.Checked = bool.Parse(dsTable.Rows[0]["IsDiscount"].ToString());
        this.txtShortDesc.Text = dsTable.Rows[0]["BookIntroduce"].ToString();
    }
是我传值的方式错了还是怎么回事?
搜索更多相关主题的帖子: color 前台 
2016-05-18 23:43
sldtk1
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:20
帖 子:624
专家分:258
注 册:2006-5-4
收藏
得分:14 
你的主键不是BookID吗?
应该没有Request["id"]这个字段吧
2016-05-21 11:20
tremere
Rank: 6Rank: 6
来 自:火星
等 级:侠之大者
帖 子:223
专家分:432
注 册:2013-3-11
收藏
得分:0 
回复 2楼 sldtk1
有的 ,我在跳转页面的时候
程序代码:
 public void AddressBack(DataListCommandEventArgs e)
    {
        Session["address"] = "";
        Session["address"] = "Defalut.aspx";
        Response.Redirect("~/showInfo.aspx?id=" + Convert.ToInt32(()));
   

    }


极品菜鸟,来学习啦,啦啦啦啦啦啦啦。。。
2016-05-21 22:15
sldtk1
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:20
帖 子:624
专家分:258
注 册:2006-5-4
收藏
得分:0 
回复 3楼 tremere
ImageButton.AutoPostBack=true;

试试让它允许post提交呢?

或者将id硬编码为1,看能不能传过去。

[此贴子已经被作者于2016-5-22 01:21编辑过]

2016-05-21 23:32
快速回复:未将对象引用设置到对象实例问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019656 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved