Datagrids and controls - part 2

  • Thread starter Thread starter Jo
  • Start date Start date
J

Jo

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.
 
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
 
Back
Top