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慕白兄还没找到联系方法,大家继续啊!
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慕白兄还没找到联系方法,大家继续啊!
------------------------
Lable lb= this.FindControl("txtID") as Label;
if(lb!=null)
{
// 你的代码
}
基类System.Web.UI.Page中的函数
Dim txtID As Label
txtID = TryCast(FindControl("label7"),Label)
现在的问题是,从字符串“产品编号:G80F20N2L-DG”到类型“Double”的转换无效。
==>
PutToCart第一个参数是int的,而你这个编号是string型的,说明传的不对,你是不是还有产品id的属性?而不是用编号
-----------------------------------------------------------你现在的错误 是字符串不能被转换成 Double
就像报的错误一样 字符串"伙" 怎么转成 Double 呢
现在就是卡在这里
Dim txtID As Label
txtID = TryCast(FindControl("label7"),Label) if txtID isnot nothing then
System.Web.HttpContext.Current.Response.Write(txtID.Text) end if
If lb IsNot Nothing Then
End If
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”,它不是数值类型。”
是不是我对这方面一点潜质都没有呢?Dim txtID As Label
txtID = TryCast(FindControl("label9"), Label)
If txtID IsNot Nothing Then
mycls.PutToCart(Int(txtID), 1)
End If有错么?
阿非哥
Int.TryParse(txtID.Text,tempInt)
mycls.PutToCart(tempInt , 1)
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
唉,怎么办,我现在的心情很矛盾,这些代码放到那个位置啊
Int.TryParse(txtID.Text, tempInt) int 出现蓝色波浪线!
可以加你QQ么!
提示是这样,非常抱歉,打扰你那么长时间了
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