selvaraj
selvaraj

Reputation: 899

FindControl in Asp.Net

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

Answers (2)

patmortech
patmortech

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

s_hewitt
s_hewitt

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

Related Questions