is this possible?

Discussion in 'ASP .Net Web Controls' started by André, Jun 29, 2006.

  1. André

    André Guest

    Hi,

    Is it possible to use the selectedValue of a dropdownlist to fill one of the
    field of a detailsview?

    I tried a lot of things, but still without succes. Here are the two methods
    i tried with two different errors. It works only when i introduce directly a
    value in "DefaultValue" (see below)

    Thanks for help
    André


    1) first method:
    asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
    ....
    InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?, @lok)"
    OldValuesParameterFormatString="original_{0}"
    ProviderName="System.Data.OleDb"
    <InsertParameters>
    <asp:parameter Name="na" Type="String" />
    <asp:parameter Name="ty" Type="String" />
    </InsertParameters>
    .....
    Code-behind:
    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    lok = DropDownList1.SelectedValue
    SqlDataSource1.InsertParameters.Add("lok", lokl)
    End Sub

    This gives: No value given for one or more required parameters
    ----------------------------------------------------------------------------
    -------------------------
    2) second method
    asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
    ....
    InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?, @lok)"
    OldValuesParameterFormatString="original_{0}"
    ProviderName="System.Data.OleDb"
    <InsertParameters>
    <asp:parameter Name="na" Type="String" />
    <asp:parameter Name="ty" Type="String" />
    <asp:parameter Name="lok" Type="String" DefaultValue="<%=lok %>" />
    </InsertParameters>
    ....

    Code-behind:
    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    lok = DropDownList1.SelectedValue
    End Sub

    This gives: You cannot add or change a record because a related record is
    required in table 'lokl'
    which means in fact that the value of the parameter is not passed!

    It works when i give directly a value: <asp:parameter Name="lok"
    Type="String" DefaultValue="1-45" />
     
    André, Jun 29, 2006
    #1
    1. Advertising

  2. hi Andre, there is built in support for what you are trying to achieve. What
    you need to use is ControlParameter in your InsertParameter just as in the
    following example code.
    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.controlparameter.aspx
    Regards,
    Alessandro Zifiglio
    "André" <> ha scritto nel messaggio
    news:%...
    > Hi,
    >
    > Is it possible to use the selectedValue of a dropdownlist to fill one of
    > the field of a detailsview?
    >
    > I tried a lot of things, but still without succes. Here are the two
    > methods
    > i tried with two different errors. It works only when i introduce directly
    > a
    > value in "DefaultValue" (see below)
    >
    > Thanks for help
    > André
    >
    >
    > 1) first method:
    > asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
    > ...
    > InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?, @lok)"
    > OldValuesParameterFormatString="original_{0}"
    > ProviderName="System.Data.OleDb"
    > <InsertParameters>
    > <asp:parameter Name="na" Type="String" />
    > <asp:parameter Name="ty" Type="String" />
    > </InsertParameters>
    > ....
    > Code-behind:
    > Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    > ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    > lok = DropDownList1.SelectedValue
    > SqlDataSource1.InsertParameters.Add("lok", lokl)
    > End Sub
    >
    > This gives: No value given for one or more required parameters
    > ----------------------------------------------------------------------------
    > -------------------------
    > 2) second method
    > asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
    > ...
    > InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?, @lok)"
    > OldValuesParameterFormatString="original_{0}"
    > ProviderName="System.Data.OleDb"
    > <InsertParameters>
    > <asp:parameter Name="na" Type="String" />
    > <asp:parameter Name="ty" Type="String" />
    > <asp:parameter Name="lok" Type="String" DefaultValue="<%=lok %>" />
    > </InsertParameters>
    > ...
    >
    > Code-behind:
    > Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    > ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    > lok = DropDownList1.SelectedValue
    > End Sub
    >
    > This gives: You cannot add or change a record because a related record is
    > required in table 'lokl'
    > which means in fact that the value of the parameter is not passed!
    >
    > It works when i give directly a value: <asp:parameter Name="lok"
    > Type="String" DefaultValue="1-45" />
    >
    >
    >
     
    Alessandro Zifiglio, Jun 29, 2006
    #2
    1. Advertising

  3. André

    André Guest

    Thanks, it works now ...


    "Alessandro Zifiglio" <AlessandroZifiglio @ -h-o-t-m-a-i-l-c-o-m> wrote in
    message news:u%...
    > hi Andre, there is built in support for what you are trying to achieve.

    What
    > you need to use is ControlParameter in your InsertParameter just as in the
    > following example code.
    >

    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.controlparameter.aspx
    > Regards,
    > Alessandro Zifiglio
    > "André" <> ha scritto nel messaggio
    > news:%...
    > > Hi,
    > >
    > > Is it possible to use the selectedValue of a dropdownlist to fill one of
    > > the field of a detailsview?
    > >
    > > I tried a lot of things, but still without succes. Here are the two
    > > methods
    > > i tried with two different errors. It works only when i introduce

    directly
    > > a
    > > value in "DefaultValue" (see below)
    > >
    > > Thanks for help
    > > André
    > >
    > >
    > > 1) first method:
    > > asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
    > > ...
    > > InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?,

    @lok)"
    > > OldValuesParameterFormatString="original_{0}"
    > > ProviderName="System.Data.OleDb"
    > > <InsertParameters>
    > > <asp:parameter Name="na" Type="String" />
    > > <asp:parameter Name="ty" Type="String" />
    > > </InsertParameters>
    > > ....
    > > Code-behind:
    > > Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    > > ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    > > lok = DropDownList1.SelectedValue
    > > SqlDataSource1.InsertParameters.Add("lok", lokl)
    > > End Sub
    > >
    > > This gives: No value given for one or more required parameters

    >
    > --------------------------------------------------------------------------

    --
    > > -------------------------
    > > 2) second method
    > > asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
    > > ...
    > > InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?,

    @lok)"
    > > OldValuesParameterFormatString="original_{0}"
    > > ProviderName="System.Data.OleDb"
    > > <InsertParameters>
    > > <asp:parameter Name="na" Type="String" />
    > > <asp:parameter Name="ty" Type="String" />
    > > <asp:parameter Name="lok" Type="String" DefaultValue="<%=lok %>" />
    > > </InsertParameters>
    > > ...
    > >
    > > Code-behind:
    > > Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    > > ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    > > lok = DropDownList1.SelectedValue
    > > End Sub
    > >
    > > This gives: You cannot add or change a record because a related record

    is
    > > required in table 'lokl'
    > > which means in fact that the value of the parameter is not passed!
    > >
    > > It works when i give directly a value: <asp:parameter Name="lok"
    > > Type="String" DefaultValue="1-45" />
    > >
    > >
    > >

    >
    >
     
    André, Jun 29, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Giagnocavo [MVP]

    Re: Is it possible....

    Michael Giagnocavo [MVP], Jun 28, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,226
    Michael Giagnocavo [MVP]
    Jun 28, 2003
  2. Ekkehard Kraemer

    Development on 98 possible at all?

    Ekkehard Kraemer, Sep 13, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    437
    Dino Chiesa [Microsoft]
    Sep 22, 2003
  3. Markus
    Replies:
    1
    Views:
    513
    Markus
    Nov 22, 2005
  4. Replies:
    4
    Views:
    308
    Kenny McCormack
    Feb 21, 2006
  5. Replies:
    10
    Views:
    501
    Chris Gonnerman
    Dec 14, 2007
Loading...

Share This Page