Hi Jo
Just noticed this follow up to your last post; here's what I said in reply
to that:
The key to making dynamically generated controls maintain their viewstate is
to generate them during the Page_Init event.
This occurs before the viewstate is deserialized, so provided you've created
the objects by this point the framework will do the rest for you. Any later
than this, and you've missed it! The viewstate is lost.
Hope this helps you; if you still can't get it working post some code and
I'll have a look.
Also: if you're using a designer (Visual Studio for example), you may find
it easier to add a template column to your datagrid, and drag a checkbox
into it rather than create it in code. Then all you have to do is populate
your dataset and bind the grid thus:
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
MyBase.OnInit(e)
Me.OleDbDataAdapter1.Fill(Me.DataSet11)
Me.DataGrid1.DataBind()
End Sub
HTH
Regards
Joe
[quoted text, click to view] "Jo" <jo.palac@cardcall.com.au> wrote in message
news:922a01c345d7$e14b75d0$a401280a@phx.gbl...
> Hi,
>
> I've tried the suggested solution but I'm still getting
> the same error. It seems that once the page postback is
> envoked the checkbox control is removed from the datagrid
> so all my changes (ticks etc) are lost. Is there a way of
> retaining the checkbox control on a postback?
>
> Thanks,
>
> Jo
>
>
>
> ***********************
> try this
>
> Dim mycheck As CheckBox = CType(dgWelcomePacks.Items
> (i).Cells(7).Controls(1), CheckBox)
>
> regards,
> Kumar.
>
>
> >-----Original Message-----
> >Hi,
> >
> >I'm doing a web application and I have a datagrid that's
> >linked to a dataset. For one of the columns in the
> >datagrid I create and add a checkbox control so that
> users
> >can easily modify the value in the dataset. I do that in
> >the following way:
> >
> >Dim mycheck As New CheckBox()
> >dgWelcomePacks.Items(i).Cells(7).Controls.Add(mycheck)
> >
> >I then mark the checkbox as ticked or unticked, depending
> >on the dataset value in the cell.
> >That all works fine.
> >Now when a user has finished with all the data in the
> >datagrid (ie ticking\unticking the checkboxes on
> different
> >rows) I want to be able to update the dataset with the
> new
> >check values. I tried by running through all the rows in
> >the datagrid and piking up the checkbox control value:
> >
> >Dim mycheck As CheckBox = CType(dgWelcomePacks.Items
> >(i).Cells(7).Controls(0), CheckBox)
> >
> >But that gives me an error saying that there is no
> control
> >in that cell (index out of range). How can that be when I
> >see the checkbox in the cell on the screen? Is there
> >something that I'm not doing when I'm initially creating
> >the checkbox and adding it as a control to the cell?
> >
> >Any help would be greately appreciated.
> >
> >Thanks in advance,
> >
> >Jo
> >
> >.