Object variable or With block variable not set

D

David C

I am getting this error in the Databound event of a GridView and I am having
a difficult time debugging. I do not get the error on every record that I
edit in the GridView. The error is occurring on the lines that start with
varCtl. (for example varCtl.CssClass = "Hide"). The other thing that is
strange is that it occurs when I click the Edit button on the GridView and
yet the error is pointing to a line in the code that only gets checked when
not in edit mode. Can anyone help? The code sample is below and then below
that is the exception thrown. Thanks.
David

Protected Sub SubfilesGridView_RowDataBound(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
'Is on a data row - not header or footer
Dim varCtl
If e.Row.RowState = DataControlRowState.Edit Then
varCtl = e.Row.FindControl("txtSeqNo")
varCtl.Attributes.Add("onchange", "DataChanged();")
varCtl = e.Row.FindControl("txtSubfile")
varCtl.Attributes.Add("onchange", "DataChanged();")
varCtl = e.Row.FindControl("LBtnSubfileCancel")
varCtl.Attributes.Add("onclick", "DataSaved();")
Else
'Add leading zeros to make seqno 4 char (e.g. 0004).
Dim strseqno As String = ""
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "SeqNo"))
Then
'Put Subfile seqno in var
strseqno =
Convert.ToString(DataBinder.Eval(e.Row.DataItem, "SeqNo"))
End If
Dim strseq As String = UtilClass.PadLeftString(strseqno,
"0", 4)
Dim strsubfile As String = ""
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "Subfile"))
Then
'Put Subfile seqno in var
strsubfile =
Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Subfile"))
End If
strseq += UtilClass.ReplaceFolderChars(strsubfile)
strPath += "\" & strseq
varCtl = e.Row.FindControl("HLViewDocs")
txtSubPath.Text = strPath
If bolNewFolder = False Then
If My.Computer.FileSystem.DirectoryExists(strPath) =
False Then
My.Computer.FileSystem.CreateDirectory(strPath)
End If
If My.Computer.FileSystem.GetFiles(strPath).Count = 0
Then
varCtl.CssClass = "Hide"
Else
varCtl.CssClass = "Show"
End If
Else
varCtl.CssClass = "Hide"
End If
End If
End If
End Sub

EXCEPTION:

An unhandled exception occurred:

Message: Object variable or With block variable not set.

Stack Trace:

at Microsoft.VisualBasic.CompilerServices.Symbols.Container..ctor(Object
Instance)

at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSet(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean
RValueBase, CallType CallType)

at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSet(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments)

at ASP.frmfileedit_aspx.SubfilesGridView_RowDataBound(Object sender,
GridViewRowEventArgs e) in http://server//Fileroom/frmFileEdit.aspx:line 486

at System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs e)

at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32
dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState,
Boolean dataBind, Object dataItem, DataControlField[] fields,
TableRowCollection rows, PagedDataSource pagedDataSource)

at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable
dataSource, Boolean dataBinding)

at
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable
data)

at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)

at
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable
data)

at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments,
DataSourceViewSelectCallback callback)

at System.Web.UI.WebControls.DataBoundControl.PerformSelect()

at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()

at System.Web.UI.WebControls.GridView.DataBind()

at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()

at System.Web.UI.WebControls.GridView.OnPreRender(EventArgs e)

at System.Web.UI.Control.PreRenderRecursiveInternal()

at System.Web.UI.Control.PreRenderRecursiveInternal()

at System.Web.UI.Control.PreRenderRecursiveInternal()

at System.Web.UI.Control.PreRenderRecursiveInternal()

at System.Web.UI.Control.PreRenderRecursiveInternal()

at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top