Reputation: 899
I'm trying to find a control in a page. The Id is available as a server control (CheckBox) This throws exception "not able to convert string to double"
Dim taskId As HtmlInputCheckBox
i =10
taskId = Me.FindControl("chkTaskOption_" + i)
taskId.Checked = True
Can any one tell me where i'm wrong.
Upvotes: 1
Views: 16831
Reputation: 10219
Your problem is that you need to use &
instead of +
to concatenate two strings in VB.NET. Change this line:
taskId = Me.FindControl("chkTaskOption_" & i)
For further reading, there's a good discussion about this in the answers to this question.
Upvotes: 3
Reputation: 4302
You might just be missing a cast of the type returned from FindControl. Or on the variable i. I can't remember if VB.net will convert for you.
i =10
Dim taskId As HtmlInputCheckBox
taskId = CType(Me.FindControl("chkTaskOption_" & i.ToString()), HtmlInputCheckBox)
taskId.Checked = True
Upvotes: 2