Why do I get above error message while executing this code:
Public Sub DropDown_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Dim list As DropDownList = CType(sender, DropDownList)
Dim cell = CType(list.Parent, TableCell)
Dim item = CType(cell.Parent, DataGridItem)
Dim index = item.ItemIndex
Dim ds As DataSet
ds = DataGrid1.DataSource
Dim row As DataRow
row = ds.Tables(0).Select("ID = '" + item.Cells(0).Text + "'")(0)
'<-- ERROR
End SubSet a break point on the line
row = ds.Tables(0).Select("ID = '" + item.Cells(0).Text + "'")(0)
and see what is null there.
Could be:
no tables in ds;
no Cells(o) in item;
no item;
select doesn't return anything
...
Debug it.
Eliyahu
"John Smith" <john.smith@.microsoft.com> wrote in message
news:%Zahg.3487$oj5.1152205@.news.siol.net...
> Why do I get above error message while executing this code:
> Public Sub DropDown_SelectedIndexChanged(ByVal sender As System.Object,
> ByVal e As System.EventArgs)
> Dim list As DropDownList = CType(sender, DropDownList)
> Dim cell = CType(list.Parent, TableCell)
> Dim item = CType(cell.Parent, DataGridItem)
> Dim index = item.ItemIndex
> Dim ds As DataSet
> ds = DataGrid1.DataSource
> Dim row As DataRow
> row = ds.Tables(0).Select("ID = '" + item.Cells(0).Text + "'")(0)
> '<-- ERROR
> End Sub
>
Thank you.
"ds" was null. It seems I need to add DataSource into Session object
somehow. Beginner mistake. It seems DataGrid1.DataSource is not persistance?
> "ds" was null. It seems I need to add DataSource into Session object
> somehow. Beginner mistake. It seems DataGrid1.DataSource is not
> persistance?
I've declared ds as global Shared variable and it works fine so far.
Just note, that global Shared variables are shared between user sessions. It
means that if there will be multiple users using the app in the same time,
they will affect each other.
Eliyahu
"John Smith" <john.smith@.microsoft.com> wrote in message
news:tWbhg.3493$oj5.1152346@.news.siol.net...
>
> I've declared ds as global Shared variable and it works fine so far.
>
> Just note, that global Shared variables are shared between user sessions.
> It
> means that if there will be multiple users using the app in the same time,
> they will affect each other.
So, should I declare it as "static" or as simple global variable (without
"shared")?
What is your data source?
"John Smith" <john.smith@.microsoft.com> wrote in message
news:Dpchg.3498$oj5.1152406@.news.siol.net...
>
> So, should I declare it as "static" or as simple global variable (without
> "shared")?
>
> What is your data source?
XML
If you can't re-populate the datasource on every postback, you can store it
in a session variable.
Eliyahu
"John Smith" <john.smith@.microsoft.com> wrote in message
news:G7ehg.3500$oj5.1153527@.news.siol.net...
>
> XML
>
> If you can't re-populate the datasource on every postback, you can store
> it
> in a session variable.
There is no other way but session object?
Thursday, March 22, 2012
System.NullReferenceException: Object reference not set to an instance of an object.
Labels:
asp,
byval,
codepublic,
dropdown_selectedindexchanged,
error,
executing,
instance,
message,
net,
object,
reference,
sub,
system,
systemnullreferenceexception
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment