Web层
<asp:DataList ID="DataList1" runat="server"  RepeatColumns="2" RepeatDirection="Horizontal" DataKeyField="GoodsID" >
                    <ItemTemplate>
                        <div id="ny_order_bg">
        <div id="left_pic"><a href="GoodsInfo.aspx?GoodsID=<%#Eval("GoodsID")%>"/><img src='<%#Eval("GoodsPic")%>' width="80" border="0"  alt="" /></div>
<div id="pic_info">
    <div id="info_tt"><a href="GoodsInfo.aspx?GoodsID=<%#Eval("GoodsID")%>"/><%#Eval("GoodsName")%><br /> <%#Eval("EnglishName")%></div>
  <div id="info_nr">产品规格:酒精度 <%#Eval("SpecName")%>(V/V)<br />市场价:<span class="red"><%#Eval("MarketPrice")%></span>元/瓶 会员价:<span class="red"><%#Eval("MemberPrice")%></span>元/瓶</div>
<div id="info_bottom"><asp:ImageButton ID="imgShoppingCart" runat="server" OnClick="imgShoppingCart_Click" ImageUrl="~/images/order.gif" CommandArgument='<%#Eval("GoodsID")%>' /><asp:HiddenField ID="GID" runat="server" /></div>
</div>
   </div>                  
                    </ItemTemplate>
                </asp:DataList>
代码:
 protected void imgShoppingCart_Click(object sender, ImageClickEventArgs e)
    {
        if (Session["UID"] == null)
        {
            ControlControls();
           // Response.Write("<script language=javascript>alert('对不起,你没有登陆,不能购买物品');window.location='Login.aspx'</script>");
        }
        else
        {
            UID = int.Parse(Session["UID"].ToString());
            ShopCartClass sc = new ShopCartClass();
            ShopCartManage shopCartManage = new ShopCartManage();
            string ID = Request.QueryString["GoodsID"];//取不出值,为空
            //gi = goodsInfoManage.SGoodInfo(int.Parse(ID));
            //sc.GoodsID = gi.GoodsID;
            sc.SumPrice = decimal.Parse(Request.QueryString["SumPrice"]);
            sc.UID = UID;
           
            int result = shopCartManage.AddShopCart(sc);
            if (result == 1)
            {                Response.Redirect("ShopCart.aspx");
            }
            else
            {
                Response.Write("<script type='text/javascript'>alert('操作失败!');history.back();</script>");
            }
        }
    }绑定的代码:
    private void GridViewBind()
    {
        AspNetPager1.RecordCount = goodsInfoManage.InfoCount(gi);
        DataList1.DataSource = goodsInfoManage.SGoodsInfo(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
        DataList1.DataBind();
        
    }存储过程:
 public List<GoodsInfo> SGoodsInfo(int pageIndex, int pageSize)
        {
            SqlParameter[] sqlParameters = {
                new SqlParameter("@pageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int)
            };
            sqlParameters[0].Value = pageIndex;
            sqlParameters[1].Value = pageSize;
            List<GoodsInfo> list = new List<GoodsInfo>();
            SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.StoredProcedure, "User_SGoodsInfo", sqlParameters);
            while (reader.Read())
            {
                GoodsInfo gi = new GoodsInfo();
                gi.GoodsID = int.Parse(reader["GoodsID"].ToString());
                gi.GoodsName = reader["GoodsName"].ToString();
                gi.EnglishName = reader["EnglishName"].ToString();
                gi.SpecName = reader["TypeName"].ToString();
                gi.GoodsPic = reader["GoodsPic"].ToString();
                gi.MarketPrice = decimal.Parse(reader["MarketPrice"].ToString());
                gi.MemberPrice = decimal.Parse(reader["MemberPrice"].ToString());
                list.Add(gi);
            }
            reader.Dispose();
            return list;
        }
        public int InfoCount(GoodsInfo gi)
        {
            return Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.StoredProcedure, "proc_GetGoodsCount", null).ToString());
        }

解决方案 »

  1.   

    在事件中,((LinkButton) e.Item.FindControl("controlID")).Text就是linkbutton的值了
      

  2.   

    Request.QueryString["GoodsID"];不是这个吧。。
    找控件的话你用FindControl方法找你LinkButton控件就可以了
    LinkButton link1 = this.DataList1.FindControl("LinkButton控件ID");
    string value = link1.Text;
      

  3.   

    “System.Web.UI.ImageClickEventArgs”并不包含“Item”的定义...