Retrieving ObjectDataSource columns

  • Thread starter Thread starter Larry Bud
  • Start date Start date
L

Larry Bud

I have a simple data object that returns two columns in a dataset, ID
and DESC, for example.

When I bind a dropdownlist to this <dataobjectmethod>, I have to
manually enter the column names for the ID and value. How do I make
the schema available?
 
Larry said:
I have a simple data object that returns two columns in a dataset, ID
and DESC, for example.

When I bind a dropdownlist to this <dataobjectmethod>, I have to
manually enter the column names for the ID and value. How do I make
the schema available?
I don't quite understand what you mean by
How do I make the schema available?
but if what you want is to avoid having to
enter the column names for the ID and value
I think you have no other option rather than specifying the
DataTextField and DataValueField properties of the DropDownList, because
their default values are string.Empty. The only case you can avoid
specifying them is if your DataSource has only one field as specified in
http://msdn2.microsoft.com/en-us/library/31723w77(VS.80).aspx:
If the data source has only one field, you do not have to explicitly
set these fields, because the control will simply display the single field.

Regards

Poli
 
Poli said:
I don't quite understand what you mean by
but if what you want is to avoid having to
I think you have no other option rather than specifying the
DataTextField and DataValueField properties of the DropDownList, because
their default values are string.Empty. The only case you can avoid
specifying them is if your DataSource has only one field as specified in
http://msdn2.microsoft.com/en-us/library/31723w77(VS.80).aspx:
If the data source has only one field, you do not have to explicitly
set these fields, because the control will simply display the single field.

Regards

Poli

The link is: http://msdn2.microsoft.com/en-us/library/31723w77(VS.80).aspx
 
I don't quite understand what you mean by
but if what you want is to avoid having to
I think you have no other option rather than specifying the
DataTextField and DataValueField properties of the DropDownList, because
their default values are string.Empty. The only case you can avoid
specifying them is if your DataSource has only one field as specified inhttp://msdn2.microsoft.com/en-us/library/31723w77(VS.80).aspx:
If the data source has only one field, you do not have to explicitly
set these fields, because the control will simply display the single field.

So anytime I bind any data object, such as a GridView, to a
datasourceobject, I have to manually specify the column names?
 
Larry said:
So anytime I bind any data object, such as a GridView, to a
datasourceobject, I have to manually specify the column names?
Not at all, what I just said applies to DropDownList and the other
ListControls (ie: ListBox, RadioButtonList, CheckBoxList, DropDownList),
with a GridView you can get the columns automatically resolved if you
set the AutoGenerateColumns property to *true*:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.autogeneratecolumns.aspx

Regards
 
I have a simple data object that returns two columns in a dataset, ID
and DESC, for example.

When I bind a dropdownlist to this <dataobjectmethod>, I have to
manually enter the column names for the ID and value. How do I make
the schema available?

ObjectDataSources do not present database schema information at Design
Time in the same way as SQl or XML sources. The output from code
behind ObjectDatasources cannot be inferred by the designer. Like all
other objects and data that are created in code their output is
entirely unknown to the system until run-time.

HTH
 
ObjectDataSources do not present database schema information at Design
Time in the same way as SQl or XML sources. The output from code
behind ObjectDatasources cannot be inferred by the designer. Like all
other objects and data that are created in code their output is
entirely unknown to the system until run-time.


Thanks, glad to know I wasn't going nuts. I was hoping there was
some way to define what the columns would be, but I guess not.
 
Back
Top