Friday, March 16, 2012

option explicit error converting system.web.ui.controls to system.web.ui.webcontrols.textb

How would I rewrite this so that I do not get the error: "Option Strict On disallows implicit conversions from 'System.Web.UI.Control' to 'System.Web.UI.WebControls.TextBox'."


Sub doinsert(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
If e.CommandName = "insertupdate" Then
Dim custst As String
Dim aprst, mayst, junst, julst, augst, sepst, octst, novst, decst, janst, febst, marst As String
Dim aprtxt, maytxt, juntxt, jultxt, augtxt, septxt, octtxt, novtxt, dectxt, jantxt, febtxt, martxt As TextBox

aprtxt = e.Item.FindControl("txtapr")
aprst = aprtxt.Text
aprtxt.Text = "0"
maytxt = e.Item.FindControl("txtmay")
mayst = maytxt.Text
maytxt.Text = "0"
juntxt = e.Item.FindControl("txtjun")
junst = juntxt.Text
juntxt.Text = "0"
jultxt = e.Item.FindControl("txtjul")
julst = jultxt.Text
jultxt.Text = "0"
augtxt = e.Item.FindControl("txtaug")
augst = augtxt.Text
augtxt.Text = "0"
septxt = e.Item.FindControl("txtsep")
sepst = septxt.Text
septxt.Text = "0"
octtxt = e.Item.FindControl("txtoct")
octst = octtxt.Text
octtxt.Text = "0"
novtxt = e.Item.FindControl("txtnov")
novst = novtxt.Text
novtxt.Text = "0"
dectxt = e.Item.FindControl("txtdec")
decst = dectxt.Text
dectxt.Text = "0"
jantxt = e.Item.FindControl("txtjan")
janst = jantxt.Text
jantxt.Text = "0"
febtxt = e.Item.FindControl("txtfeb")
febst = febtxt.Text
febtxt.Text = "0"
martxt = e.Item.FindControl("txtmar")
marst = martxt.Text
martxt.Text = "0"

testlabel3.Text = aprst
If radiocustomer.Checked = True Then
strcust = DropDowncust1.SelectedItem.Text
strcustid = DropDowncust1.SelectedItem.Value
Else
strcust = prospecttxt.Text
strcustid = "0000"
End If

Probably you need this cast at relevant points:

aprtxt = CType(e.Item.FindControl("txtapr"), TextBox)
Thank you, that is what I needed.

0 comments:

Post a Comment