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...
>> "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.
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...
>> 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?
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...
>> 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.
There is no other way but session object?
John Smith wrote:
>> 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?
If you need it to be session-specific, the session object makes it easy.
Sure, you can create a global hashtable keyed by some property of the
users of your application, but
1. this hashtable could get rather large, and
2. if you are not careful, bugs are hard to avoid.
Just out of curiosity, what is your objection to the session object?
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
> Just out of curiosity, what is your objection to the session object?
I am beginner and I have never used it before. I'll try it now.
John Smith wrote:
>> Just out of curiosity, what is your objection to the session object?
> I am beginner and I have never used it before. I'll try it now.
Ah!
I typically use a pattern like this in my pages:
Private _CachedDS as dataset
Private Propery CachedDS() as dataset
Get
If _CachedDS Is Nothing Then
If Not Session("CachedDS") Is Nothing Then
_CachedDS = CType(Session("CachedDS"), dataset)
End If
End If
Return _CachedDS
End Get
Set(ByVal Value As dataset)
Session("CachedDS") = Value
_CachedDS = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
BindDataGrid()
End If
End Sub
...
Sub BindDataGrid
Dim ds as dataset
if CachedDS Is Nothing then
FillDataSet()
End If
'bind the grid
Dim ds as dataset=CachedDS
With DataGrid1
.DataSource=ds
.DataMember = ...
.DataBind
End With
End Sub
Sub FillDataSet()
Try
CachedDS = DataLayer.RetrieveData(parms)
Catch ex
'handle error
End Try
End Sub
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
if not CachedDS is Nothing then
ds = CachedDS
Else
'throw an error? call FillDataset? up to you.
End If
Dim row As DataRow
row = ds.Tables(0).Select("ID = '" + item.Cells(0).Text +
"'")(0)
etc.
HTH,
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
John Smith wrote:
>> 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")?
You should probably store it in Session rather than declaring it "Global
Shared"
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
0 comments:
Post a Comment