Move sqldatasource from client side to server side

Posted on 2009-04-28
Last Modified: 2012-05-06
Hi Experts,
I have a combobox and gridview that use a SqlDataSource to fill them. All works correctly now, but I want to include an all option in the dropdown and use this in the selectcommand. This requires more dynamic code and I am not able to produce this.

I would be able to do this server side, but I do not know how to define a SqlDataSource server side that can be used client side.

Best regards, MB

                    ConnectionString="<%$ ConnectionStrings:Connection %>"
                    SelectCommand="SELECT *
                                   FROM [Bunkerings] WHERE [Vessel] = @VesselName
                                   ORDER BY [ReportDateTimeGMT] DESC "
                    UpdateCommand="UPDATE [Bunkerings] SET [Supplier] = @Supplier, Broker=@Broker, [CST] = @CST, [DueDate] = @DueDate,
                                   [PriceHFOHS] = @PriceHFOHS, [PriceHFOLS] = @PriceHFOLS, [PriceMDOHS] = @PriceMDOHS, [PriceMDOLS] = @PriceMDOLS,
                                   [BunkerTakenHFOHS] = @BunkerTakenHFOHS, [BunkerTakenHFOLS] = @BunkerTakenHFOLS, [BunkerTakenMDOHS] = @BunkerTakenMDOHS,
                                   [BunkerTakenMDOLS] = @BunkerTakenMDOLS, [AdditionalCosts] = @AdditionalCosts, [Remarks] = @Remarks
                                   WHERE [BunkeringID] = @BunkeringID ">
                            PropertyName ="text"
                            Type="String" />
                        <asp:Parameter Name="BunkeringID" Type="String" />
                        <asp:Parameter Name="Supplier" Type="String" />
                        <asp:Parameter Name="CST" Type="Decimal" />
                        <asp:Parameter Name="Broker" Type="String" />
                        <asp:Parameter Name="DueDate" Type="DateTime" />
                        <asp:Parameter Name="PriceHFOHS" Type="Decimal" />
                        <asp:Parameter Name="PriceHFOLS" Type="Decimal" />
                        <asp:Parameter Name="PriceMDOHS" Type="Decimal" />
                        <asp:Parameter Name="PriceMDOLS" Type="Decimal" />
                        <asp:Parameter Name="BunkerTakenHFOHS" Type="Decimal" />
                        <asp:Parameter Name="BunkerTakenHFOLS" Type="Decimal" />
                        <asp:Parameter Name="BunkerTakenMDOHS" Type="Decimal" />
                        <asp:Parameter Name="BunkerTakenMDOLS" Type="Decimal" />
                        <asp:Parameter Name="AdditionalCosts" Type="String" />
                        <asp:Parameter Name="Remarks" Type="String" />
                    ConnectionString="<%$ ConnectionStrings:Connection %>"
                    SelectCommand="SELECT DISTINCT [VesselName] FROM [Vessels] WHERE [Status]='10' ORDER BY [VesselName] ASC">
Question by:mark_norge
    LVL 14

    Accepted Solution


    Use as below

     <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" DataSource="BunkeringDataSource" DataTextField="" DataValueField="">
            <asp:ListItem Text="All" Value="All"></asp:ListItem>

    The AppendDataBoundItems = true ensures that the databound items are appended after the All item and it won't overwrite or remove any items previously added to the dropdownlist.

    Author Comment

    Thanks for your reply, very helpful,

    I am using Telerik controls and with this tip it was easy to achieve the first part. Now I have the option all, but how do I use this in the sql select command.
    The select command needs a where clause in case of a specific vessel and does not need this if all vessels need to be shown. Server side this would be no problem, but how do I use a dynamic select command client side.

    Regards, MB
    LVL 14

    Expert Comment

    Use this statement

    strQuery =  "Select * from tablename where columnname = '" & DropDownList.SelectedValue  & "%'"

    Author Closing Comment

    Thanks for your help. I ended up using the following WHERE clause:
    WHERE  ( @Vessel  = 'All vessels' or [Vessel] = @Vessel )


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now