Dim txtID As Label
                txtID = e.Item.FindControl("label7")
                mycls.PutToCart(Int(txtID.Text), 1)
而puttocart的代码是
    Public Sub PutToCart(ByVal proid As Integer, ByVal num As Integer)
        Dim proList, numList As String
        proList = System.Web.HttpContext.Current.Session("prolist")
        numList = System.Web.HttpContext.Current.Session("numList")
        If Len(proList) = 0 Then
            System.Web.HttpContext.Current.Session("booklist") = proid
            System.Web.HttpContext.Current.Session("numList") = num
        ElseIf InStr(proList & ",", proid & ",") <= 0 Then
            System.Web.HttpContext.Current.Session("booklist") = proid & "," & proList
            System.Web.HttpContext.Current.Session("numList") = num & "," & numList
        End If
    End Sub
这是老师写的,txtID是label,label7是关于ID的标签
问题是,老师写的时候txtID = e.Item.FindControl("label7")是在datalist里面的
而我现在说写的就是普通的页面,e.Item.FindControl,如果在普通的页面怎么表达呢?
是那,那个ID:cpp2017慕白兄还没找到联系方法,大家继续啊!

解决方案 »

  1.   

    普通的页面
    ------------------------
     Lable lb= this.FindControl("txtID") as Label;
     if(lb!=null)
     {
       // 你的代码
      }
      

  2.   

    FindControl("<Control ID>")
    基类System.Web.UI.Page中的函数
      

  3.   

    Lable lb= this.FindControl("ID号") as Label;
      

  4.   

    如下:
    Dim txtID As Label
                    txtID = TryCast(FindControl("label7"),Label)
      

  5.   

    还是不行,现在的问题是从字符串“产品编号:G80F20N2L-DG”到类型“Double”的转换无效。
      

  6.   

    还是不行,能不能再次麻烦您呢,
    现在的问题是,从字符串“产品编号:G80F20N2L-DG”到类型“Double”的转换无效。
      

  7.   

    还是不行,现在的问题是从字符串“产品编号:G80F20N2L-DG”到类型“Double”的转换无效。
    ==>
    PutToCart第一个参数是int的,而你这个编号是string型的,说明传的不对,你是不是还有产品id的属性?而不是用编号
      

  8.   

    是的,我刚才测试来,是我太大意了,然后我改为label9(这个是ID)的然后出现“从字符串“label”到类型“Double”的转换无效。”然后我赋值给label9.text=伙,而出现了“从字符串“伙”到类型“Double”的转换无效。”所以,不是label转换double的转换无效,而是里面的值,那您觉得怎么改呢
      

  9.   

    我没别的意思,只是想说慕白兄很忙,但是看到帖子的时候 是会及时回复的。
    -----------------------------------------------------------你现在的错误 是字符串不能被转换成 Double
    就像报的错误一样 字符串"伙" 怎么转成 Double 呢
      

  10.   

    是啊,但是,我改为1就可以了,而1是ID里面的值,但是,问题是,我怎么获取这个ID呢
    现在就是卡在这里
      

  11.   

    完整的如下:
    Dim txtID As Label
    txtID = TryCast(FindControl("label7"),Label) if txtID isnot nothing then
          
            System.Web.HttpContext.Current.Response.Write(txtID.Text) end if
      

  12.   

    Dim lb As Lable = TryCast(Me.FindControl("lblId"), Label)
    If lb IsNot Nothing Then
    End If
      

  13.   

    我是这样写的If Session("memberid") = "" Then
                    Response.Write("<script language='javascript'>alert('请先登录');</script>")
                    Exit Sub
                Else
                    Dim txtID As Label
                    txtID = TryCast(FindControl("label9"), Label)
                    If txtID IsNot Nothing Then                    System.Web.HttpContext.Current.Response.Write(txtID.Text)
                        mycls.PutToCart(Int(txtID), 1)
                    End If
    但是,还是出错“参数“Number”的类型为“System.Web.UI.WebControls.Label”,它不是数值类型。”
      

  14.   

    mycls.PutToCart(Int(txtID), 1)=>mycls.PutToCart(Int(txtID.Text), 1)
      

  15.   

    我不知道你们个个都那么写,我其实,真的不是很明白,唉,好烦啊!
    是不是我对这方面一点潜质都没有呢?Dim txtID As Label
                    txtID = TryCast(FindControl("label9"), Label)
                    If txtID IsNot Nothing Then
                        mycls.PutToCart(Int(txtID), 1)
                    End If有错么?
      

  16.   

    你的意思是叫我改TEXT是吧。还是老问题,我真的不知道怎么办啊!烦啊!
    阿非哥
      

  17.   

    其实你现在的写法 是有潜在BUG 的应如下Dim tempInt as Integer =-1
    Int.TryParse(txtID.Text,tempInt)
     mycls.PutToCart(tempInt , 1)
      

  18.   


    Dim txtID As Label
                    txtID = TryCast(FindControl("label9"), Label)
                    If txtID IsNot Nothing Then
    Dim tempInt as Integer =-1
    Int.TryParse(txtID.Text,tempInt)
     mycls.PutToCart(tempInt , 1)
                    End If
      

  19.   


    唉,怎么办,我现在的心情很矛盾,这些代码放到那个位置啊
     Int.TryParse(txtID.Text, tempInt) int 出现蓝色波浪线!
    可以加你QQ么!
      

  20.   

    INT 还是有蓝色波浪线“没有可访问的“int”接受此项目的参数,因此重载失败”
    提示是这样,非常抱歉,打扰你那么长时间了
      

  21.   


    Dim txtID As Label
            txtID = TryCast(FindControl("label9"), Label)        If txtID IsNot Nothing Then            Dim tempInt As Integer
                Integer.TryParse(txtID.Text, tempInt)            mycls.PutToCart(tempInt, 1)
            End If