CodeSmith Community
Your Code. Your Way. Faster!

FormView Insert Parameters

Latest post 09-21-2008 11:16 PM by velum. 8 replies.
  • 01-08-2008 11:05 AM

    • alexlea
    • Top 500 Contributor
    • Joined on 04-25-2006
    • Posts 11
    • Points 265

    FormView Insert Parameters

     Hi,

     I am trying to insert a record from a FormView using the DataSource defined as:

    <data:RedemptionIdentifierDataSource id="rids" runat="server" selectmethod="GetByPromotionId" insertdatetimenames="CreatedDate" oninserting="OnRedemptionIdentifier_Inserting">        
            <Parameters>

                       <asp:QueryStringParameter name="PromotionId" querystringfield="pid" type="Int32"></asp:QueryStringParameter>                       
       
        </Parameters>

    </data:RedemptionIdentifierDataSource>

     However, the QueryStringParameter's value which is not defined by the FormView (in this case PromotionId) does not get inserted. Does this mean that the Parameters collection applies only when selecting? 

     I can get round this by putting the logic I need in the Inserting event, but it seems that this should work much as it would with ObjectDataSource and it's insertparameters collection. 


    • Post Points: 35
  • 01-11-2008 10:32 AM In reply to

    • velum
    • Top 25 Contributor
    • Joined on 07-14-2006
    • Montréal, Qc, Canada
    • Posts 189
    • Points 4,731

    Re: FormView Insert Parameters

    Hi Alexlea!

    I believe that the  QueryStringParameter is only a parameter of the GetByPromotionId method. If you want to insert the PromotionId using the FormView, you will need to add a web control to the FormView bound to PromotionId. Something like:

    <asp:HiddenField ID="HiddenField1" Value='<%# Bind("PromotionId") %>' runat="server" />

    This would work if PromotionId is auto-number.

    Cheers!

    JF

     

    • Post Points: 35
  • 01-14-2008 1:31 PM In reply to

    • alexlea
    • Top 500 Contributor
    • Joined on 04-25-2006
    • Posts 11
    • Points 265

    Re: FormView Insert Parameters

     Hi and thanks for the reply JF. 

    Neat trick that! Unfortunately the PromotionId is not auto-number, it is a foreign key to elsewhere.

    Your post implies that maybe other forms of parameters may apply on insert, any idea what these are? Perhaps I could use one of them instead. I see this a fairly common scenario for my application.

    Cheers

    Alex


    • Post Points: 65
  • 07-29-2008 10:29 PM In reply to

    • Xcalibur
    • Not Ranked
    • Joined on 06-10-2008
    • Posts 6
    • Points 150

    Re: FormView Insert Parameters

    I too am having this exact problem.

    My situation is that i have set up a master/details scenario with 2 gridviews, both are using typed .nettiers data sources.  It all works fine, but when you try to insert a record on the second grid it fails, basically complaining that the foreign key (retrieved from the first grid) is null.  In other words, it doesnt seem the typed data source is retrieving the foreign key when inserting, but does so when selecting.  For reference here is the typed data source im using for the second grid:

     <data:DiagnosisDataSource runat="server" id="dsDiagnoses" EnablePaging="False" SelectMethod="GetByPatientId" EnableCaching="False">

     

     

     

     

    <Parameters>

     

     

    <asp:ControlParameter Name="PatientId" ControlID="gridPatients" PropertyName="SelectedValue" Type="Int32" />

     

     

    </Parameters>

     

     

    </data:DiagnosisDataSource>

     

     

    If i replace the above with a standard ASP.NET SQL data source, where i am able to specify the control parameter in the Insert section it works perfectly!  So it seems to me that the typed data source does not retrieve the control parameter value when inserting ...  It must be possible as this is a very common scenario in web apps.  Can someone explain how to achieve this using .netTiers data sources.  Cheers.

    • Post Points: 35
  • 09-11-2008 11:08 AM In reply to

    • davewells
    • Not Ranked
    • Joined on 08-21-2008
    • London
    • Posts 8
    • Points 215

    Re: FormView Insert Parameters

    I'm having the same problem. Did you resolve this or does anyone have any ideas?

    Thanks

    Dave

    • Post Points: 65
  • 09-14-2008 12:33 AM In reply to

    • Xcalibur
    • Not Ranked
    • Joined on 06-10-2008
    • Posts 6
    • Points 150

    Re: FormView Insert Parameters

    Reply |Contact |Answer

    Hi Dave

    I hate to tell you this but the way i solved it is by f*(&ing off .netTiers and using standard datasources as in the end i found that it really wasnt offering me much at all and had sever limitations.  Man my code is much cleaner now!

    Im still of the opinion that this is a bug in the strongly typed datasources - because you cannot set the insert parameters in any way and it just doesnt seem to absorb the primary key field that you point it to.

    However i often found with .netTiers that there will be some obscure forum post somewhere that explains an atrribute you can use that isnt popping up in the intellisense - perhaps there is one such post somewhere that will be able to help you with this issue or perhaps its obvious and im stupid.

    In any case, very sorry i cant help you further if you do find a solution please post here!

    cheers

    • Post Points: 35
  • 09-21-2008 4:23 AM In reply to

    • zoz
    • Not Ranked
    • Joined on 09-18-2008
    • Posts 4
    • Points 80

    Re: FormView Insert Parameters

    I have a similar problem. Can you share with us the solution you have found to fix the problem ?

    • Post Points: 5
  • 09-21-2008 10:57 PM In reply to

    • velum
    • Top 25 Contributor
    • Joined on 07-14-2006
    • Montréal, Qc, Canada
    • Posts 189
    • Points 4,731

    Re: FormView Insert Parameters

    Hi Alex!

    This reply comes late, but it might be useful to others. I don't know of any trick to assign a value to a form field dynamically outside from writing some code-behind. With code-behind however, I know two ways of doing what you want to do. As far as I understand, you want to insert the value of the pid query-string parameter when the form is submitted.

    1. You could have a hidden field for PromotionId with some code-behind to assign a value to it:

    <asp:HiddenField ID="hfPromotionId" value='<%# Bind("PromotionId") %>' OnDataBound="hfPromotionId_DataBound" runat="server" />

    Then, once the hidden field would be data-bound, the hfPromotionId_DataBound method would be called and you could change its value to whatever you want; For instance, the pid query-string parameter value:

    protected void hfPromotionId_DataBound(object sender, EventArgs e)
    {
        ((HiddenField)sender).value = Request.QueryString["pid"].ToString();
    }

    2. Or you could use a second method where the method in the code-behind would be attached to the data-source. You've already defined the data-source so that it calls the OnRedemptionIdentifier_Inserting() method, so it would be quite easy to add the following line to it:

            protected void OnRedemptionIdentifier_Inserting(object sender, ObjectDataSourceMethodEventArgs e)

            {
                ...
                e.InputParameters["PromotionId"] = Request.QueryString["pid"].ToString();
            }

    To tell you the truth, I've always been quite disappointed by the fact that there is no simpler and more elegant way to do this in ASP.NET.

    Cheers!

    JF

    • Post Points: 5
  • 09-21-2008 11:16 PM In reply to

    • velum
    • Top 25 Contributor
    • Joined on 07-14-2006
    • Montréal, Qc, Canada
    • Posts 189
    • Points 4,731

    Re: FormView Insert Parameters

    Reply |Contact |Answer

    Hi Dave and Xcalibur!

    If my understanding of what you want to do is correct, I would use a OneToManyGridRelationship (<data:OneToManyGridRelationship ID="..." runat="server">). There are not many examples for it unfortunately, but they talk about it on this thread: http://community.codesmithtools.com/forums/p/5798/22688.aspx

    On my project, I'm mainly dealing with n-n relationships though, so I use the ManyToManyListRelationship. There is a good thread about it here: http://community.codesmithtools.com/forums/p/3033/12586.aspx#12586

    Cheers!

    JF

     

    • Post Points: 5
Page 1 of 1 (9 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems