Home All Groups Group Topic Archive Search About

GridView, ObjectDataSOurce, and enum parameter for select

Author
15 Mar 2006 12:00 AM
David Thielen
Hi;

I want to create an ObjectDataSource that calls a method of mine that then
does a select on the database. I want to pass an enum to the method that
calls the select. This enum is in my database access code.

I then want a GridView that gets it's data from the ObjectDataSource and it
passes the enum value to the ObjectDataSource. I will actually have 2 grid
views on the page, one for each of the two enum values.

How can I do this?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Author
15 Mar 2006 12:52 AM
Phillip Williams
The Select parameter type property only accept the following values:
http://msdn2.microsoft.com/en-us/library/system.typecode(VS.80).aspx

So if you have an enum like this:
private enum DatabaseAccesCode
{
     Access1=0,
     Access2=1
}
Then you would pass the static value in the Select Parameters of the
objectDataSource like this:
<SelectParameters>
     <asp:Parameter Type="int32" DefaultValue="1" Name="AccessCode"/>
</SelectParameters>

If this enum value will be supplied as an input from another object on the
page, e.g. when the user changes the selection on a dropdownlist then you can
use the <asp:ControlParameter> instead.


Show quoteHide quote
"David Thielen" wrote:

> Hi;
>
> I want to create an ObjectDataSource that calls a method of mine that then
> does a select on the database. I want to pass an enum to the method that
> calls the select. This enum is in my database access code.
>
> I then want a GridView that gets it's data from the ObjectDataSource and it
> passes the enum value to the ObjectDataSource. I will actually have 2 grid
> views on the page, one for each of the two enum values.
>
> How can I do this?
>
> --
> thanks - dave
> david_at_windward_dot_net
> http://www.windwardreports.com
>
Author
15 Mar 2006 1:33 AM
David Thielen
Hi;

I can do that. How do I pass the value in the GridView control to the
ObjectDataSource control?

And is it a problem to use the same ObjectDataSource control for two
GridView controls, with each grid using a different parameter?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



Show quoteHide quote
"Phillip Williams" wrote:

> The Select parameter type property only accept the following values:
> http://msdn2.microsoft.com/en-us/library/system.typecode(VS.80).aspx
>
> So if you have an enum like this:
> private enum DatabaseAccesCode
> {
>      Access1=0,
>      Access2=1
> }
> Then you would pass the static value in the Select Parameters of the
> objectDataSource like this:
> <SelectParameters>
>      <asp:Parameter Type="int32" DefaultValue="1" Name="AccessCode"/>
> </SelectParameters>
>
> If this enum value will be supplied as an input from another object on the
> page, e.g. when the user changes the selection on a dropdownlist then you can
> use the <asp:ControlParameter> instead.
>
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "David Thielen" wrote:
>
> > Hi;
> >
> > I want to create an ObjectDataSource that calls a method of mine that then
> > does a select on the database. I want to pass an enum to the method that
> > calls the select. This enum is in my database access code.
> >
> > I then want a GridView that gets it's data from the ObjectDataSource and it
> > passes the enum value to the ObjectDataSource. I will actually have 2 grid
> > views on the page, one for each of the two enum values.
> >
> > How can I do this?
> >
> > --
> > thanks - dave
> > david_at_windward_dot_net
> > http://www.windwardreports.com
> >
Author
15 Mar 2006 1:50 AM
Phillip Williams
To pass a field value from the GridView to a parameter add the field to the
GridView.DataKeys: http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeys.aspx

Assuming that the enum value field is the first datakey, then in your select
parameters, you would have
<asp:ControlParameter ControlID="GridView1" Name="DataBaseAccess"
     PropertyName="SelectedDataKey.Values[0]"  Type="int32"/>

As for your second question, it is not a problem.
Show quoteHide quote
"David Thielen" wrote:

> Hi;
>
> I can do that. How do I pass the value in the GridView control to the
> ObjectDataSource control?
>
> And is it a problem to use the same ObjectDataSource control for two
> GridView controls, with each grid using a different parameter?
>
> --
> thanks - dave
> david_at_windward_dot_net
> http://www.windwardreports.com
>
>
>
> "Phillip Williams" wrote:
>
> > The Select parameter type property only accept the following values:
> > http://msdn2.microsoft.com/en-us/library/system.typecode(VS.80).aspx
> >
> > So if you have an enum like this:
> > private enum DatabaseAccesCode
> > {
> >      Access1=0,
> >      Access2=1
> > }
> > Then you would pass the static value in the Select Parameters of the
> > objectDataSource like this:
> > <SelectParameters>
> >      <asp:Parameter Type="int32" DefaultValue="1" Name="AccessCode"/>
> > </SelectParameters>
> >
> > If this enum value will be supplied as an input from another object on the
> > page, e.g. when the user changes the selection on a dropdownlist then you can
> > use the <asp:ControlParameter> instead.
> >
> >
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "David Thielen" wrote:
> >
> > > Hi;
> > >
> > > I want to create an ObjectDataSource that calls a method of mine that then
> > > does a select on the database. I want to pass an enum to the method that
> > > calls the select. This enum is in my database access code.
> > >
> > > I then want a GridView that gets it's data from the ObjectDataSource and it
> > > passes the enum value to the ObjectDataSource. I will actually have 2 grid
> > > views on the page, one for each of the two enum values.
> > >
> > > How can I do this?
> > >
> > > --
> > > thanks - dave
> > > david_at_windward_dot_net
> > > http://www.windwardreports.com
> > >
Author
16 Mar 2006 7:50 AM
Steven Cheng[MSFT]
Hi Dave,

I think Phillip has provided you some good ideas on this. You can supply
the parameter for the Select method through Control parameter or
querystring  or other supported parameter source.  BTW, I think it better
to use separate datasource controls for different GridView if they'll be
supplied different parameters (for selection).

Please let me know if you have any other questions or particular
requirement.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)