最近做一个项目,用到页面传值,代码出来以后,运行出了问题,提示:字符串格式不正确,请问各位大大原因,谢谢了!代码如下:html:
<asp:DataList ID="DataList1" runat="server" Height="222px" 
              RepeatDirection="Horizontal" Width="756px" RepeatColumns="5" >
                              <ItemTemplate>
                                  <a href="/Model/Product/ProductDetail.aspx?id=productID">
                                  <img  src='<%# DataBinder.Eval(Container.DataItem, "pic")%>' />
                                  </a>
                              </ItemTemplate>
                          </asp:DataList>
这是用datalist绑定图片,然后他图片有个链接,然后传值过去。本页cs代码: protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                databinding();
                getinfo();
            }
        }        protected void databinding()
        {
            JustyleOnline.Model.Product.Business.Product pro = new         JustyleOnline.Model.Product.Business.Product();
            DataSet ds= pro.GetNewProduct();
            //string str = ds.Tables[0].Rows.Count.ToString();
            //JustyleOnline.Core.JS.Alert(str);
            DataList1.DataSource = ds.Tables[0].DefaultView;
            DataList1.DataBind();
        }这是页面的数据绑定代码,其中获取到product的一些值。接下来是接受页面的代码: if (!Page.IsPostBack)
            {
                
                //显示更新数据
                //若ID为空,则修改管理员自己的信息
                if (Request.QueryString["ID"] == null)
                {
                   
                }
                else
                {
                    productID = Convert.ToInt32(Request.QueryString["ID"].ToString());//就是在这一步提示字符串的格式不正确的错误。
                 }附:productID这个字段的数据类型是int型
求助各位!!!

解决方案 »

  1.   

    <a href='/Model/Product/ProductDetail.aspx?id=<%# DataBinder.Eval(Container.DataItem, "productID",{0})%>'>
      

  2.   

    productID 这个是数据库的一个字段吗
      

  3.   

    <a href='/Model/Product/ProductDetail.aspx?id=<%# DataBinder.Eval(Container.DataItem, "productID")%>'>
      

  4.   

    嗯,productID是数据库字段,然后接受 页面的确是有接收到数据,但是提示格式不正确
    接受页面的那个判断语句,已经有判断是不是有接收到值。
      

  5.   

     if (Request.QueryString["ID"] == null)
      {
        
      }
      else
      {
      productID = Convert.ToInt32(Request.QueryString["ID"].ToString());//就是在这一步提示字符串的格式不正确的错误。
      }
    应该这样写
     if (Request.QueryString["id"] == null)
      {
        
      }
      else
      {
      productID = Convert.ToInt32(Request.QueryString["id"].ToString());
     }
      

  6.   

    <a href="/Model/Product/ProductDetail.aspx?id=productID">
    你这样传过去的值是productID,当然不能转换成int型了。。
    <a href="/Model/Product/ProductDetail.aspx?id=<%=productID%>">试试而且
    productID = Convert.ToInt32(Request.QueryString["ID"].ToString());
    你这里的ID要注意大小写,应该是一致的,即使没影响代码标准些有好处的。
      

  7.   

    呵呵呵 ,OKOK,问题解决了
    1l兄,不好意思啊,你的代码可以,我用它解决了
    咳咳,7l,你的那句“<%=productID%>”,貌似有些问题
    OK,没事,都有分,虽然不多,大奖将就着吧
    谢谢了
      

  8.   

    <a href="/Model/Product/ProductDetail.aspx?id=productID">这传值 错误啦!!