注册 登录
编程论坛 ASP.NET技术论坛

未将对象引用设置到对象实例问题

tremere 发布于 2016-05-18 23:43, 6455 次点击
在前台页面我放了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();
    }
是我传值的方式错了还是怎么回事?
3 回复
#2
sldtk12016-05-21 11:20
你的主键不是BookID吗?
应该没有Request["id"]这个字段吧
#3
tremere2016-05-21 22:15
回复 2楼 sldtk1
有的 ,我在跳转页面的时候
程序代码:
public void AddressBack(DataListCommandEventArgs e)
    {
        Session["address"] = "";
        Session["address"] = "Defalut.aspx";
        Response.Redirect("~/showInfo.aspx?id=" + Convert.ToInt32(()));
   

    }

#4
sldtk12016-05-21 23:32
回复 3楼 tremere
ImageButton.AutoPostBack=true;

试试让它允许post提交呢?

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

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

1