.NET 2 > ObjectDataSource in GridView

S

syl

Hello

I am trying to create a "easy to use" gridview with filters (dropdownlist in
headers), sorting...and much more....
In order to do that, i prefer to use a objectdatasource (ODS) beacause
filters and sort are automaticly managed....

I would like that my own gridview (inherited from
system.web.ui.webcontrols.gridview) includes a ODS which I expose by
properties. In that way, I use this "advanced" grid view without adding on
each page the ODS......

well.....my problem is that I cant add a ODS in my gridview....
in the gridview, in the onload or OnPreRender method, I try to affect the
datasourceid property to the ID of the "inside" ODS...but i get always the
same error :
<<<the DataSourceID of "mygridview" must be the ID of a IDataSource control.
A control with the ID "_ods" was noty found>>>

Am I missing something?
Do you have a idea?

Thanks a lot!!!

Bye
Syl

PS :
My code looks like that :

-------------my grid view-------------------------
Public Class GridView
Inherits Common.Web.UI.WebControls.GridView

Private WithEvents _ods As ObjectDatasource

Public ReadOnly Property odsDataSource() As ObjectDatasource
Get
If _ods Is Nothing Then
_ods = New ObjectDatasource
_ods.ID = "_ods"
_ods.EnableViewState = False
End If
Return _ods
End Get
End Property

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
Me.Controls.Add(_ods)
Me.DataSourceID = _ods.ID
End Sub

.....a lot of things with OnRowCreated, OnPreRender, and much
more.....!!!....

End Class


---------------use of my grid view in a webcontrol-------------------

Partial Class webControls_ThingList
Inherits System.Web.UI.UserControl

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'GV is my gridView in the ThingList control
GV.odsDataSource.TypeName = "my_type"
GV.odsDataSource.SelectMethod = "function_name_for_data_source"
End Sub

End Class
 
S

syl

Hi!

Problem solve!

in fact, I cant do a gridview.controls.add(ODS)
I must add the ODS in the parent control (ASPX or ASCX)


bye!
syl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top