Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ObjectDataSource SelectMethod
Message
De
05/07/2010 14:37:04
 
 
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01471404
Message ID:
01471437
Vues:
29
>>>>OK, I found some sample code on-line and this is what I can try:
>>>>
>>>>
<asp:ObjectDataSource ID="odsRiders" runat="server" SelectMethod="GetRidersAndWaiversByPlan"
>>>>                                    TypeName="SamaanSystems.IAS.Business.Plan">
>>>>                                    <selectparameters>
>>>>                                        <asp:querystringparameter name="planPK"  querystringfield="planpk" defaultvalue="-1" />
>>>>                                    </selectparameters>
>>>>                                    </asp:ObjectDataSource>
>>>>
>>>>However, I am not using a querystring to pass in the value I need. I can access the value in the aspx.cs file like this: this.oPolicy.Entity.PlanFK
>>>>
>>>>So how would I use that in the aspx file?
>>>
>>>For your case the only way is to specify generic parameter Parameter Name = "PlanPK" type = "Int32"
>>>
>>>and then set your parameter's value in Selecting event of ObjectDataSource.
>>>
>>>I have a blog on a similar problem (for SQLDataSource), never tried myself this technique with ObjectDataSource. When you get it to work, post your code and I'll update my blog with your sample:
>>>
>>>See here
>>>http://blogs.lessthandot.com/index.php/WebDev/WebDesignGraphicsStyling/setting-sqldatasource-parameter-from-the
>>
>>Thanks again, but I couldn't find the stuff you referenced on the blog that was specific/similar to what I am trying to do (or at least I couldn't understand it, which is the more likely thing).
>
>See also http://msdn.microsoft.com/en-us/library/system.typecode.aspx There is no Guid type, you can use String as type.
>>
>>I think that what you are trying to tell me is:
>>
>>1. create the ObjectDataSource like this:
>>
>>
<asp:ObjectDataSource ID="odsRiders" runat="server" SelectMethod="GetRidersAndWaiversByPlan"
>>                                    TypeName="SamaanSystems.IAS.Business.Plan">
>>                                    <selectparameters>
>>                                        <asp:parameter name="planPK" type="Guid" />
>>                                    </selectparameters>
>>                                    </asp:ObjectDataSource>
>>
>>2. in my code behind file create method like this:
>>
>>
        protected void odsRiders_Selecting(object sender, SqlDataSourceCommandEventArgs e)
>>        {
>>            e.Command.Parameters["@PlanPK"].Value = this.oPolicy.Entity.PlanFK;
>>        }
>>
>>Is that correct?
>>
>>Another issue is that I can't create a Guid parameter and all my primary keys are Guids/uniqueidentifiers.
>
>Yes, very close. You need to add OnSelecting = "odsRiders_Selecting" in the ObjectDataSource definition. Also I'm not sure if the code will need adjustments (first of all, obviously, the type of second parameter in Selecting event will be different).
>
>As I said, the listed code is for SQLDataSource and for ObjectDataSource the code will be slightly different. You may also try alternative solution by Don Freeman listed in that blog as well (using DefaultValue property).
>
>See also http://msdn.microsoft.com/en-us/library/system.typecode.aspx
>As you see, there is no Guid type, you need to use String as type.

OK, I think the code should look more like this:
        protected void odsRiders_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            e.InputParameters["planPK"] = this.oPolicy.Entity.PlanFK;
        }
And the String worked (I think, but haven't tested properly yet).

Thanks
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform