Nightmare with ASP.NET 
Author Message
 Nightmare with ASP.NET

Hi, am having some troubles getting used to ASP.NET.
(working in VB.NET using VS 2003)
I am trying to create an editable/updatable DataGrid but
have encountered a range of problems.

Firstly what I have done is create a DataSet ( by using
visual DataAdapter generated dataset).

Then in the onload I do

if not page.ispostback then
  MyDataAdapter.fill(MyDataSet)
  Session("Ds")=MyDataSet
  MyDataGrid.dataBind()
end if

this works fine ( up to ths point)

now if I build my own function

private sub DataGridBind()
   MyDataSet=Session("Ds")
   MyDataGrid.dataBind()
end sub
nothing happens
following the code in the de{*filter*} shows me that when I
set the value of MyDataSet=Session("Ds") it gives me a
value of nothing...

then my next problem is I can't make it editable, even by
handling the OnEdit event and
doing code like---

Sub MyDataGrid_Edit(sender As Object, e As
DataGridCommandEventArgs)
        MyDataGrid.EditItemIndex = e.Item.ItemIndex
        DataGridBind
End Sub

Someone please help

Regards

Jarrad



Sun, 11 Dec 2005 08:10:26 GMT  
 Nightmare with ASP.NET
When you are visually designing the datagrid you set a property for it's
datasource. You are not doing that when you do it programmatically... so you
need:

if not page.ispostback then
   MyDataAdapter.fill(MyDataSet)
   myDataGrid.dataSource = myDataSet.tables(0) 'MUST SET DATASOURCE!
   Session("Ds")=MyDataSet
   MyDataGrid.dataBind()
end if

I'm of course assuming that the adapter has data to put...

I'm not sure why your session would be "nothing".  If your datagrid starts
binding now and it's still "nothing".  Post back and let us know.

Quote:
> Hi, am having some troubles getting used to ASP.NET.
> (working in VB.NET using VS 2003)
> I am trying to create an editable/updatable DataGrid but
> have encountered a range of problems.

> Firstly what I have done is create a DataSet ( by using
> visual DataAdapter generated dataset).

> Then in the onload I do

> if not page.ispostback then
>   MyDataAdapter.fill(MyDataSet)
>   Session("Ds")=MyDataSet
>   MyDataGrid.dataBind()
> end if

> this works fine ( up to ths point)

> now if I build my own function

> private sub DataGridBind()
>    MyDataSet=Session("Ds")
>    MyDataGrid.dataBind()
> end sub
> nothing happens
> following the code in the de{*filter*} shows me that when I
> set the value of MyDataSet=Session("Ds") it gives me a
> value of nothing...

> then my next problem is I can't make it editable, even by
> handling the OnEdit event and
> doing code like---

> Sub MyDataGrid_Edit(sender As Object, e As
> DataGridCommandEventArgs)
>         MyDataGrid.EditItemIndex = e.Item.ItemIndex
>         DataGridBind
> End Sub

> Someone please help

> Regards

> Jarrad



Sun, 11 Dec 2005 09:17:10 GMT  
 Nightmare with ASP.NET
Hi MC,

I set the datasource visually, so if I do ...
MyDataAdapter.fill(MyDataSet)
MyDataGrid.DataBind()

It is filled with the appropriate data.

Upon further investigation, if I do: -

private sub BindGrid()
   MyDataAdapterlfill(MyDataSet)
   MyDataGrid.DataBind()
end sub

Private Sub DataGrid1_EditCommand(ByVal source As Object,
ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles DataGrid1.EditCommand
   Me.DatGrid1.EditItemIndex=e.Item.ItemIndex
   BindGrid()
end sub

The actual Edit will work as it is supposed to, but I
can't seem to put the dataset into Session object then
retrieve it....

Jarrad

Quote:
>-----Original Message-----
>When you are visually designing the datagrid you set a
property for it's
>datasource. You are not doing that when you do it

programmatically... so you
Quote:
>need:

>if not page.ispostback then
>   MyDataAdapter.fill(MyDataSet)
>   myDataGrid.dataSource = myDataSet.tables(0) 'MUST SET
DATASOURCE!
>   Session("Ds")=MyDataSet
>   MyDataGrid.dataBind()
>end if

>I'm of course assuming that the adapter has data to
put...

>I'm not sure why your session would be "nothing".  If

your datagrid starts
Quote:
>binding now and it's still "nothing".  Post back and let
us know.


>> Hi, am having some troubles getting used to ASP.NET.
>> (working in VB.NET using VS 2003)
>> I am trying to create an editable/updatable DataGrid
but
>> have encountered a range of problems.

>> Firstly what I have done is create a DataSet ( by using
>> visual DataAdapter generated dataset).

>> Then in the onload I do

>> if not page.ispostback then
>>   MyDataAdapter.fill(MyDataSet)
>>   Session("Ds")=MyDataSet
>>   MyDataGrid.dataBind()
>> end if

>> this works fine ( up to ths point)

>> now if I build my own function

>> private sub DataGridBind()
>>    MyDataSet=Session("Ds")
>>    MyDataGrid.dataBind()
>> end sub
>> nothing happens
>> following the code in the de{*filter*} shows me that when I
>> set the value of MyDataSet=Session("Ds") it gives me a
>> value of nothing...

>> then my next problem is I can't make it editable, even
by
>> handling the OnEdit event and
>> doing code like---

>> Sub MyDataGrid_Edit(sender As Object, e As
>> DataGridCommandEventArgs)
>>         MyDataGrid.EditItemIndex = e.Item.ItemIndex
>>         DataGridBind
>> End Sub

>> Someone please help

>> Regards

>> Jarrad

>.



Sun, 11 Dec 2005 09:29:22 GMT  
 Nightmare with ASP.NET
So, when are you calling the fill and bind methods the first time?  In
page_load?  If so, make sure you are not in postback. Simply hitting refresh
(if you have previously posted data) will not call the bind method if you
are in postback.   To be safe, and see if this is the problem, you could
move that code out of the "If page.ispostback" condition, so it will be
called every time, then see if it works the first time.  If so, then it's a
postback issue.

How are you confirming that the session is "nothing"?  Are you testing this
conditionally?eg:

MyDataAdapter.fill(MyDataSet)
Session("Ds") = myDataSet
IF session("Ds") is nothing then
    response.write("session ds is nothing!")
ELSE
Try
    response.write(cType(session("Ds"),
dataSet).tables(0).rows(0).item("someKnownColumn")))
Catch ex as exception
    response.write ex.message
End Try
END IF

And see what that ends up writing.  I've never tried putting a dataset into
a session before, so I'm shooting in the dark, but it should work, as far as
I know. Just FYI, it's not a "best practice" to put that kind of data in a
session. ;o)


Quote:
> Hi MC,

> I set the datasource visually, so if I do ...
> MyDataAdapter.fill(MyDataSet)
> MyDataGrid.DataBind()

> It is filled with the appropriate data.

> Upon further investigation, if I do: -

> private sub BindGrid()
>    MyDataAdapterlfill(MyDataSet)
>    MyDataGrid.DataBind()
> end sub

> Private Sub DataGrid1_EditCommand(ByVal source As Object,
> ByVal e As
> System.Web.UI.WebControls.DataGridCommandEventArgs)
> Handles DataGrid1.EditCommand
>    Me.DatGrid1.EditItemIndex=e.Item.ItemIndex
>    BindGrid()
> end sub

> The actual Edit will work as it is supposed to, but I
> can't seem to put the dataset into Session object then
> retrieve it....

> Jarrad

> >-----Original Message-----
> >When you are visually designing the datagrid you set a
> property for it's
> >datasource. You are not doing that when you do it
> programmatically... so you
> >need:

> >if not page.ispostback then
> >   MyDataAdapter.fill(MyDataSet)
> >   myDataGrid.dataSource = myDataSet.tables(0) 'MUST SET
> DATASOURCE!
> >   Session("Ds")=MyDataSet
> >   MyDataGrid.dataBind()
> >end if

> >I'm of course assuming that the adapter has data to
> put...

> >I'm not sure why your session would be "nothing".  If
> your datagrid starts
> >binding now and it's still "nothing".  Post back and let
> us know.


> >> Hi, am having some troubles getting used to ASP.NET.
> >> (working in VB.NET using VS 2003)
> >> I am trying to create an editable/updatable DataGrid
> but
> >> have encountered a range of problems.

> >> Firstly what I have done is create a DataSet ( by using
> >> visual DataAdapter generated dataset).

> >> Then in the onload I do

> >> if not page.ispostback then
> >>   MyDataAdapter.fill(MyDataSet)
> >>   Session("Ds")=MyDataSet
> >>   MyDataGrid.dataBind()
> >> end if

> >> this works fine ( up to ths point)

> >> now if I build my own function

> >> private sub DataGridBind()
> >>    MyDataSet=Session("Ds")
> >>    MyDataGrid.dataBind()
> >> end sub
> >> nothing happens
> >> following the code in the de{*filter*} shows me that when I
> >> set the value of MyDataSet=Session("Ds") it gives me a
> >> value of nothing...

> >> then my next problem is I can't make it editable, even
> by
> >> handling the OnEdit event and
> >> doing code like---

> >> Sub MyDataGrid_Edit(sender As Object, e As
> >> DataGridCommandEventArgs)
> >>         MyDataGrid.EditItemIndex = e.Item.ItemIndex
> >>         DataGridBind
> >> End Sub

> >> Someone please help

> >> Regards

> >> Jarrad

> >.



Sun, 11 Dec 2005 12:22:28 GMT  
 Nightmare with ASP.NET
Testing that session is nothing with similar code to what
you describe,  then if it isn't nothing I do
MyDataSet = cType(session("Ds"),dataSet)

If putting the dataset into the session object is not the
right way to go, what is the alternative? as i will have
concurrent users I figured that the session object would
be limited to a particular user (plus the amount of data
stored was small).

It is not a postback issue as far as I can see
jarrad

Quote:
>-----Original Message-----
>So, when are you calling the fill and bind methods the
first time?  In
>page_load?  If so, make sure you are not in postback.

Simply hitting refresh
Quote:
>(if you have previously posted data) will not call the
bind method if you
>are in postback.   To be safe, and see if this is the
problem, you could
>move that code out of the "If page.ispostback"

condition, so it will be
Quote:
>called every time, then see if it works the first time.  
If so, then it's a
>postback issue.

>How are you confirming that the session is "nothing"?  

Are you testing this
Quote:
>conditionally?eg:

>MyDataAdapter.fill(MyDataSet)
>Session("Ds") = myDataSet
>IF session("Ds") is nothing then
>    response.write("session ds is nothing!")
>ELSE
>Try
>    response.write(cType(session("Ds"),
>dataSet).tables(0).rows(0).item("someKnownColumn")))
>Catch ex as exception
>    response.write ex.message
>End Try
>END IF

>And see what that ends up writing.  I've never tried

putting a dataset into
Quote:
>a session before, so I'm shooting in the dark, but it

should work, as far as

- Show quoted text -

Quote:
>I know. Just FYI, it's not a "best practice" to put that
kind of data in a
>session. ;o)



>> Hi MC,

>> I set the datasource visually, so if I do ...
>> MyDataAdapter.fill(MyDataSet)
>> MyDataGrid.DataBind()

>> It is filled with the appropriate data.

>> Upon further investigation, if I do: -

>> private sub BindGrid()
>>    MyDataAdapterlfill(MyDataSet)
>>    MyDataGrid.DataBind()
>> end sub

>> Private Sub DataGrid1_EditCommand(ByVal source As
Object,
>> ByVal e As
>> System.Web.UI.WebControls.DataGridCommandEventArgs)
>> Handles DataGrid1.EditCommand
>>    Me.DatGrid1.EditItemIndex=e.Item.ItemIndex
>>    BindGrid()
>> end sub

>> The actual Edit will work as it is supposed to, but I
>> can't seem to put the dataset into Session object then
>> retrieve it....

>> Jarrad

>> >-----Original Message-----
>> >When you are visually designing the datagrid you set a
>> property for it's
>> >datasource. You are not doing that when you do it
>> programmatically... so you
>> >need:

>> >if not page.ispostback then
>> >   MyDataAdapter.fill(MyDataSet)
>> >   myDataGrid.dataSource = myDataSet.tables(0) 'MUST
SET
>> DATASOURCE!
>> >   Session("Ds")=MyDataSet
>> >   MyDataGrid.dataBind()
>> >end if

>> >I'm of course assuming that the adapter has data to
>> put...

>> >I'm not sure why your session would be "nothing".  If
>> your datagrid starts
>> >binding now and it's still "nothing".  Post back and
let
>> us know.


>> >> Hi, am having some troubles getting used to ASP.NET.
>> >> (working in VB.NET using VS 2003)
>> >> I am trying to create an editable/updatable DataGrid
>> but
>> >> have encountered a range of problems.

>> >> Firstly what I have done is create a DataSet ( by
using
>> >> visual DataAdapter generated dataset).

>> >> Then in the onload I do

>> >> if not page.ispostback then
>> >>   MyDataAdapter.fill(MyDataSet)
>> >>   Session("Ds")=MyDataSet
>> >>   MyDataGrid.dataBind()
>> >> end if

>> >> this works fine ( up to ths point)

>> >> now if I build my own function

>> >> private sub DataGridBind()
>> >>    MyDataSet=Session("Ds")
>> >>    MyDataGrid.dataBind()
>> >> end sub
>> >> nothing happens
>> >> following the code in the de{*filter*} shows me that
when I
>> >> set the value of MyDataSet=Session("Ds") it gives
me a
>> >> value of nothing...

>> >> then my next problem is I can't make it editable,
even
>> by
>> >> handling the OnEdit event and
>> >> doing code like---

>> >> Sub MyDataGrid_Edit(sender As Object, e As
>> >> DataGridCommandEventArgs)
>> >>         MyDataGrid.EditItemIndex = e.Item.ItemIndex
>> >>         DataGridBind
>> >> End Sub

>> >> Someone please help

>> >> Regards

>> >> Jarrad

>> >.

>.



Sun, 11 Dec 2005 13:05:22 GMT  
 Nightmare with ASP.NET
Ok... so what happens when you:

MyDataSet = cType(session("Ds"),dataSet)

Do you get an error, or only when you access MyDataSet? I guess I need more
info about what the error is.

A session should always be the last place you put a variable because it
persists so long.  Typically it's 20 minutes. THat's 20 minutes this piece
of information (which for something like a dataset could be very large) is
floating around in the system, even if your user has moved on to another
site. For a typical variable, it only persists for, what, a few miliseconds?
If you have a large number of users, this can compound into a problem pretty
quickly.

Since a dataset is almost always just a reflection of some other data (like
a database table or result of a sql query), it might not make sense to just
duplicate that data into a session variable when you could just access it
directly as needed, but of course it depends on your situation.  If you are
doing something like a shopping cart then I'd use something like an array of
the purchased item ids to be store in the session variable... that would be
much,much smaller than a dataset.

If you are just needing to maintain a data between postbacks, then storing
the data in the viewstate might be a better alternative since that data only
persists for the current page.

ctype(viewstate("Ds"),dataSet) = myDataSet

But don't quote me on that since I'm not sure a dataset is serializeable
(which any data that goes into something like a viewstate or webservice
needs to be).

Sorry you are having so many problems, and if I'm not much help.

MC D


Quote:
> Testing that session is nothing with similar code to what
> you describe,  then if it isn't nothing I do
> MyDataSet = cType(session("Ds"),dataSet)

> If putting the dataset into the session object is not the
> right way to go, what is the alternative? as i will have
> concurrent users I figured that the session object would
> be limited to a particular user (plus the amount of data
> stored was small).

> It is not a postback issue as far as I can see
> jarrad

> >-----Original Message-----
> >So, when are you calling the fill and bind methods the
> first time?  In
> >page_load?  If so, make sure you are not in postback.
> Simply hitting refresh
> >(if you have previously posted data) will not call the
> bind method if you
> >are in postback.   To be safe, and see if this is the
> problem, you could
> >move that code out of the "If page.ispostback"
> condition, so it will be
> >called every time, then see if it works the first time.
> If so, then it's a
> >postback issue.

> >How are you confirming that the session is "nothing"?
> Are you testing this
> >conditionally?eg:

> >MyDataAdapter.fill(MyDataSet)
> >Session("Ds") = myDataSet
> >IF session("Ds") is nothing then
> >    response.write("session ds is nothing!")
> >ELSE
> >Try
> >    response.write(cType(session("Ds"),
> >dataSet).tables(0).rows(0).item("someKnownColumn")))
> >Catch ex as exception
> >    response.write ex.message
> >End Try
> >END IF

> >And see what that ends up writing.  I've never tried
> putting a dataset into
> >a session before, so I'm shooting in the dark, but it
> should work, as far as
> >I know. Just FYI, it's not a "best practice" to put that
> kind of data in a
> >session. ;o)



> >> Hi MC,

> >> I set the datasource visually, so if I do ...
> >> MyDataAdapter.fill(MyDataSet)
> >> MyDataGrid.DataBind()

> >> It is filled with the appropriate data.

> >> Upon further investigation, if I do: -

> >> private sub BindGrid()
> >>    MyDataAdapterlfill(MyDataSet)
> >>    MyDataGrid.DataBind()
> >> end sub

> >> Private Sub DataGrid1_EditCommand(ByVal source As
> Object,
> >> ByVal e As
> >> System.Web.UI.WebControls.DataGridCommandEventArgs)
> >> Handles DataGrid1.EditCommand
> >>    Me.DatGrid1.EditItemIndex=e.Item.ItemIndex
> >>    BindGrid()
> >> end sub

> >> The actual Edit will work as it is supposed to, but I
> >> can't seem to put the dataset into Session object then
> >> retrieve it....

> >> Jarrad

> >> >-----Original Message-----
> >> >When you are visually designing the datagrid you set a
> >> property for it's
> >> >datasource. You are not doing that when you do it
> >> programmatically... so you
> >> >need:

> >> >if not page.ispostback then
> >> >   MyDataAdapter.fill(MyDataSet)
> >> >   myDataGrid.dataSource = myDataSet.tables(0) 'MUST
> SET
> >> DATASOURCE!
> >> >   Session("Ds")=MyDataSet
> >> >   MyDataGrid.dataBind()
> >> >end if

> >> >I'm of course assuming that the adapter has data to
> >> put...

> >> >I'm not sure why your session would be "nothing".  If
> >> your datagrid starts
> >> >binding now and it's still "nothing".  Post back and
> let
> >> us know.


> >> >> Hi, am having some troubles getting used to ASP.NET.
> >> >> (working in VB.NET using VS 2003)
> >> >> I am trying to create an editable/updatable DataGrid
> >> but
> >> >> have encountered a range of problems.

> >> >> Firstly what I have done is create a DataSet ( by
> using
> >> >> visual DataAdapter generated dataset).

> >> >> Then in the onload I do

> >> >> if not page.ispostback then
> >> >>   MyDataAdapter.fill(MyDataSet)
> >> >>   Session("Ds")=MyDataSet
> >> >>   MyDataGrid.dataBind()
> >> >> end if

> >> >> this works fine ( up to ths point)

> >> >> now if I build my own function

> >> >> private sub DataGridBind()
> >> >>    MyDataSet=Session("Ds")
> >> >>    MyDataGrid.dataBind()
> >> >> end sub
> >> >> nothing happens
> >> >> following the code in the de{*filter*} shows me that
> when I
> >> >> set the value of MyDataSet=Session("Ds") it gives
> me a
> >> >> value of nothing...

> >> >> then my next problem is I can't make it editable,
> even
> >> by
> >> >> handling the OnEdit event and
> >> >> doing code like---

> >> >> Sub MyDataGrid_Edit(sender As Object, e As
> >> >> DataGridCommandEventArgs)
> >> >>         MyDataGrid.EditItemIndex = e.Item.ItemIndex
> >> >>         DataGridBind
> >> >> End Sub

> >> >> Someone please help

> >> >> Regards

> >> >> Jarrad

> >> >.

> >.



Mon, 12 Dec 2005 00:25:09 GMT  
 Nightmare with ASP.NET
I don't get an error, the MyDataSet just holds nothing
then, which is a bit confusing as  have cut and pasted
the query and ran in SQL Query analyser with data
returned.
MyDataAdapter.fill(MyDataSet)
Session("Ds")=MyDataSet
MyDataSet = cType(session("Ds"),dataSet)
If IsNothing(MyDataSet) then
  ... throw exception
endif

With regards to storing in the Session variable, I plan
to explicitly free the variable on page unload.

May be time to do a bit more reading/learning on using
viewstate to stores variable, because  haven't used it
before....

To do a similar functionality as above.. how would I do
it in viewstate? (just a simple hint!!)

thanks
Jarrad

Quote:
>-----Original Message-----
>Ok... so what happens when you:

>MyDataSet = cType(session("Ds"),dataSet)

>Do you get an error, or only when you access MyDataSet?
I guess I need more
>info about what the error is.

>A session should always be the last place you put a
variable because it
>persists so long.  Typically it's 20 minutes. THat's 20
minutes this piece
>of information (which for something like a dataset could
be very large) is
>floating around in the system, even if your user has
moved on to another
>site. For a typical variable, it only persists for,

what, a few miliseconds?
Quote:
>If you have a large number of users, this can compound

into a problem pretty
Quote:
>quickly.

>Since a dataset is almost always just a reflection of

some other data (like
Quote:
>a database table or result of a sql query), it might not
make sense to just
>duplicate that data into a session variable when you

could just access it
Quote:
>directly as needed, but of course it depends on your

situation.  If you are
Quote:
>doing something like a shopping cart then I'd use

something like an array of
Quote:
>the purchased item ids to be store in the session

variable... that would be
Quote:
>much,much smaller than a dataset.

>If you are just needing to maintain a data between

postbacks, then storing
Quote:
>the data in the viewstate might be a better alternative

since that data only
Quote:
>persists for the current page.

>ctype(viewstate("Ds"),dataSet) = myDataSet

>But don't quote me on that since I'm not sure a dataset
is serializeable
>(which any data that goes into something like a

viewstate or webservice

- Show quoted text -

Quote:
>needs to be).

>Sorry you are having so many problems, and if I'm not
much help.

>MC D



>> Testing that session is nothing with similar code to
what
>> you describe,  then if it isn't nothing I do
>> MyDataSet = cType(session("Ds"),dataSet)

>> If putting the dataset into the session object is not
the
>> right way to go, what is the alternative? as i will
have
>> concurrent users I figured that the session object
would
>> be limited to a particular user (plus the amount of
data
>> stored was small).

>> It is not a postback issue as far as I can see
>> jarrad

>> >-----Original Message-----
>> >So, when are you calling the fill and bind methods the
>> first time?  In
>> >page_load?  If so, make sure you are not in postback.
>> Simply hitting refresh
>> >(if you have previously posted data) will not call the
>> bind method if you
>> >are in postback.   To be safe, and see if this is the
>> problem, you could
>> >move that code out of the "If page.ispostback"
>> condition, so it will be
>> >called every time, then see if it works the first
time.
>> If so, then it's a
>> >postback issue.

>> >How are you confirming that the session is "nothing"?
>> Are you testing this
>> >conditionally?eg:

>> >MyDataAdapter.fill(MyDataSet)
>> >Session("Ds") = myDataSet
>> >IF session("Ds") is nothing then
>> >    response.write("session ds is nothing!")
>> >ELSE
>> >Try
>> >    response.write(cType(session("Ds"),
>> >dataSet).tables(0).rows(0).item("someKnownColumn")))
>> >Catch ex as exception
>> >    response.write ex.message
>> >End Try
>> >END IF

>> >And see what that ends up writing.  I've never tried
>> putting a dataset into
>> >a session before, so I'm shooting in the dark, but it
>> should work, as far as
>> >I know. Just FYI, it's not a "best practice" to put
that
>> kind of data in a
>> >session. ;o)



>> >> Hi MC,

>> >> I set the datasource visually, so if I do ...
>> >> MyDataAdapter.fill(MyDataSet)
>> >> MyDataGrid.DataBind()

>> >> It is filled with the appropriate data.

>> >> Upon further investigation, if I do: -

>> >> private sub BindGrid()
>> >>    MyDataAdapterlfill(MyDataSet)
>> >>    MyDataGrid.DataBind()
>> >> end sub

>> >> Private Sub DataGrid1_EditCommand(ByVal source As
>> Object,
>> >> ByVal e As
>> >> System.Web.UI.WebControls.DataGridCommandEventArgs)
>> >> Handles DataGrid1.EditCommand
>> >>    Me.DatGrid1.EditItemIndex=e.Item.ItemIndex
>> >>    BindGrid()
>> >> end sub

>> >> The actual Edit will work as it is supposed to, but
I
>> >> can't seem to put the dataset into Session object
then
>> >> retrieve it....

>> >> Jarrad

>> >> >-----Original Message-----
>> >> >When you are visually designing the datagrid you
set a
>> >> property for it's
>> >> >datasource. You are not doing that when you do it
>> >> programmatically... so you
>> >> >need:

>> >> >if not page.ispostback then
>> >> >   MyDataAdapter.fill(MyDataSet)
>> >> >   myDataGrid.dataSource = myDataSet.tables
(0) 'MUST
>> SET
>> >> DATASOURCE!
>> >> >   Session("Ds")=MyDataSet
>> >> >   MyDataGrid.dataBind()
>> >> >end if

>> >> >I'm of course assuming that the adapter has data to
>> >> put...

>> >> >I'm not sure why your session would be "nothing".  
If
>> >> your datagrid starts
>> >> >binding now and it's still "nothing".  Post back
and
>> let
>> >> us know.


>> >> >> Hi, am having some troubles getting used to
ASP.NET.
>> >> >> (working in VB.NET using VS 2003)
>> >> >> I am trying to create an editable/updatable
DataGrid
>> >> but
>> >> >> have encountered a range of problems.

>> >> >> Firstly what I have done is create a DataSet ( by
>> using
>> >> >> visual DataAdapter generated dataset).

>> >> >> Then in the onload I do

>> >> >> if not page.ispostback then
>> >> >>   MyDataAdapter.fill(MyDataSet)
>> >> >>   Session("Ds")=MyDataSet
>> >> >>   MyDataGrid.dataBind()
>> >> >> end if

>> >> >> this works fine ( up to ths point)

>> >> >> now if I build my own function

>> >> >> private sub DataGridBind()
>> >> >>    MyDataSet=Session("Ds")
>> >> >>    MyDataGrid.dataBind()
>> >> >> end sub
>> >> >> nothing happens
>> >> >> following the code in the de{*filter*} shows me that
>> when I
>> >> >> set the value of MyDataSet=Session("Ds") it gives
>> me a
>> >> >> value of nothing...

>> >> >> then my next problem is I can't make it editable,
>> even
>> >> by
>> >> >> handling the OnEdit event and
>> >> >> doing code like---

>> >> >> Sub MyDataGrid_Edit(sender As Object, e As
>> >> >> DataGridCommandEventArgs)
>> >> >>         MyDataGrid.EditItemIndex =
e.Item.ItemIndex
>> >> >>         DataGridBind
>> >> >> End Sub

>> >> >> Someone please help

>> >> >> Regards

>> >> >> Jarrad

>> >> >.

>> >.

>.



Mon, 12 Dec 2005 06:50:58 GMT  
 Nightmare with ASP.NET
If I were doing it in a viewstate I'd do something like:

      Public Property theDs() As DataSet
            Get
                  Return CType(viewstate("Ds"), DataSet)
            End Get
            Set(ByVal Value As DataSet)
                  viewstate("Ds") = Value
            End Set
      End Property

and then access it by

me.theDs = myDataSet

etc.

Sorry I'm not of more help on your problem.  Check out
http://www.*-*-*.com/
information on your situation.

Best of luck,

MC D.

Quote:
> I don't get an error, the MyDataSet just holds nothing
> then, which is a bit confusing as  have cut and pasted
> the query and ran in SQL Query analyser with data
> returned.
> MyDataAdapter.fill(MyDataSet)
> Session("Ds")=MyDataSet
> MyDataSet = cType(session("Ds"),dataSet)
> If IsNothing(MyDataSet) then
>   ... throw exception
> endif

> With regards to storing in the Session variable, I plan
> to explicitly free the variable on page unload.

> May be time to do a bit more reading/learning on using
> viewstate to stores variable, because  haven't used it
> before....

> To do a similar functionality as above.. how would I do
> it in viewstate? (just a simple hint!!)

> thanks
> Jarrad

> >-----Original Message-----
> >Ok... so what happens when you:

> >MyDataSet = cType(session("Ds"),dataSet)

> >Do you get an error, or only when you access MyDataSet?
> I guess I need more
> >info about what the error is.

> >A session should always be the last place you put a
> variable because it
> >persists so long.  Typically it's 20 minutes. THat's 20
> minutes this piece
> >of information (which for something like a dataset could
> be very large) is
> >floating around in the system, even if your user has
> moved on to another
> >site. For a typical variable, it only persists for,
> what, a few miliseconds?
> >If you have a large number of users, this can compound
> into a problem pretty
> >quickly.

> >Since a dataset is almost always just a reflection of
> some other data (like
> >a database table or result of a sql query), it might not
> make sense to just
> >duplicate that data into a session variable when you
> could just access it
> >directly as needed, but of course it depends on your
> situation.  If you are
> >doing something like a shopping cart then I'd use
> something like an array of
> >the purchased item ids to be store in the session
> variable... that would be
> >much,much smaller than a dataset.

> >If you are just needing to maintain a data between
> postbacks, then storing
> >the data in the viewstate might be a better alternative
> since that data only
> >persists for the current page.

> >ctype(viewstate("Ds"),dataSet) = myDataSet

> >But don't quote me on that since I'm not sure a dataset
> is serializeable
> >(which any data that goes into something like a
> viewstate or webservice
> >needs to be).

> >Sorry you are having so many problems, and if I'm not
> much help.

> >MC D



> >> Testing that session is nothing with similar code to
> what
> >> you describe,  then if it isn't nothing I do
> >> MyDataSet = cType(session("Ds"),dataSet)

> >> If putting the dataset into the session object is not
> the
> >> right way to go, what is the alternative? as i will
> have
> >> concurrent users I figured that the session object
> would
> >> be limited to a particular user (plus the amount of
> data
> >> stored was small).

> >> It is not a postback issue as far as I can see
> >> jarrad

> >> >-----Original Message-----
> >> >So, when are you calling the fill and bind methods the
> >> first time?  In
> >> >page_load?  If so, make sure you are not in postback.
> >> Simply hitting refresh
> >> >(if you have previously posted data) will not call the
> >> bind method if you
> >> >are in postback.   To be safe, and see if this is the
> >> problem, you could
> >> >move that code out of the "If page.ispostback"
> >> condition, so it will be
> >> >called every time, then see if it works the first
> time.
> >> If so, then it's a
> >> >postback issue.

> >> >How are you confirming that the session is "nothing"?
> >> Are you testing this
> >> >conditionally?eg:

> >> >MyDataAdapter.fill(MyDataSet)
> >> >Session("Ds") = myDataSet
> >> >IF session("Ds") is nothing then
> >> >    response.write("session ds is nothing!")
> >> >ELSE
> >> >Try
> >> >    response.write(cType(session("Ds"),
> >> >dataSet).tables(0).rows(0).item("someKnownColumn")))
> >> >Catch ex as exception
> >> >    response.write ex.message
> >> >End Try
> >> >END IF

> >> >And see what that ends up writing.  I've never tried
> >> putting a dataset into
> >> >a session before, so I'm shooting in the dark, but it
> >> should work, as far as
> >> >I know. Just FYI, it's not a "best practice" to put
> that
> >> kind of data in a
> >> >session. ;o)



> >> >> Hi MC,

> >> >> I set the datasource visually, so if I do ...
> >> >> MyDataAdapter.fill(MyDataSet)
> >> >> MyDataGrid.DataBind()

> >> >> It is filled with the appropriate data.

> >> >> Upon further investigation, if I do: -

> >> >> private sub BindGrid()
> >> >>    MyDataAdapterlfill(MyDataSet)
> >> >>    MyDataGrid.DataBind()
> >> >> end sub

> >> >> Private Sub DataGrid1_EditCommand(ByVal source As
> >> Object,
> >> >> ByVal e As
> >> >> System.Web.UI.WebControls.DataGridCommandEventArgs)
> >> >> Handles DataGrid1.EditCommand
> >> >>    Me.DatGrid1.EditItemIndex=e.Item.ItemIndex
> >> >>    BindGrid()
> >> >> end sub

> >> >> The actual Edit will work as it is supposed to, but
> I
> >> >> can't seem to put the dataset into Session object
> then
> >> >> retrieve it....

> >> >> Jarrad

> >> >> >-----Original Message-----
> >> >> >When you are visually designing the datagrid you
> set a
> >> >> property for it's
> >> >> >datasource. You are not doing that when you do it
> >> >> programmatically... so you
> >> >> >need:

> >> >> >if not page.ispostback then
> >> >> >   MyDataAdapter.fill(MyDataSet)
> >> >> >   myDataGrid.dataSource = myDataSet.tables
> (0) 'MUST
> >> SET
> >> >> DATASOURCE!
> >> >> >   Session("Ds")=MyDataSet
> >> >> >   MyDataGrid.dataBind()
> >> >> >end if

> >> >> >I'm of course assuming that the adapter has data to
> >> >> put...

> >> >> >I'm not sure why your session would be "nothing".
> If
> >> >> your datagrid starts
> >> >> >binding now and it's still "nothing".  Post back
> and
> >> let
> >> >> us know.


> >> >> >> Hi, am having some troubles getting used to
> ASP.NET.
> >> >> >> (working in VB.NET using VS 2003)
> >> >> >> I am trying to create an editable/updatable
> DataGrid
> >> >> but
> >> >> >> have encountered a range of problems.

> >> >> >> Firstly what I have done is create a DataSet ( by
> >> using
> >> >> >> visual DataAdapter generated dataset).

> >> >> >> Then in the onload I do

> >> >> >> if not page.ispostback then
> >> >> >>   MyDataAdapter.fill(MyDataSet)
> >> >> >>   Session("Ds")=MyDataSet
> >> >> >>   MyDataGrid.dataBind()
> >> >> >> end if

> >> >> >> this works fine ( up to ths point)

> >> >> >> now if I build my own function

> >> >> >> private sub DataGridBind()
> >> >> >>    MyDataSet=Session("Ds")
> >> >> >>    MyDataGrid.dataBind()
> >> >> >> end sub
> >> >> >> nothing happens
> >> >> >> following the code in the de{*filter*} shows me that
> >> when I
> >> >> >> set the value of MyDataSet=Session("Ds") it gives
> >> me a
> >> >> >> value of nothing...

> >> >> >> then my next problem is I can't make it editable,
> >> even
> >> >> by
> >> >> >> handling the OnEdit event and
> >> >> >> doing code like---

> >> >> >> Sub MyDataGrid_Edit(sender As Object, e As
> >> >> >> DataGridCommandEventArgs)
> >> >> >>         MyDataGrid.EditItemIndex =
> e.Item.ItemIndex
> >> >> >>         DataGridBind
> >> >> >> End Sub

> >> >> >> Someone please help

> >> >> >> Regards

> >> >> >> Jarrad

> >> >> >.

> >> >.

> >.



Mon, 12 Dec 2005 11:35:38 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Survey on ASP/VS6.0 versus ASP.NET/VS.NET

2. Visual Basic.NET , ASP or ASP.NET

3. VB6/ASP vs .NET/ASP.NET development

4. vote for top VB.net Nightmare

5. ADO.NET with ASP.NET using VB.NET

6. asp response.write in asp.net

7. Application State in ASP and ASP.NET

8. ASP Request Object into ASP.Net

9. ASP - ASP.NET quick question about including files..

10. url encoding ASP vs ASP.net

11. New article on porting ASP pages to ASP .NET available on MSDN

12. ASP & ASP.NET

 

 
Powered by phpBB® Forum Software