|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
GridView, ObjectDataSOurce, and enum parameter for selectHi;
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? 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 > 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? 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 > > 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 > > > 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.)
Cant get user-entered values in GridView
Fitting a character on a small button Scrolling DG w/a Fixed Header DataGrid1.DataSource = ds.Tables(2) Treeview SelectedNodeChanged event not firing GridView Multiple Select Buttons it's really important thing to solve How can I create a new excel file in webbrowser? Help! About the webBrowser! Dynamically adding Views to Multiview control |
|||||||||||||||||||||||