?
Solved

Get combobox value and use in sql query client side

Posted on 2009-04-20
5
Medium Priority
?
285 Views
Last Modified: 2012-05-06
Hello Experts,

I have a dropdown and grid. To fill the grid I use an sql query that should use the selecteditem of the combobox. I have the following but this does not work.

Regards, MB

<asp:SqlDataSource ID="BunkeringDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:Connection %>"
                    ProviderName="System.Data.SqlClient" SelectCommand="SELECT BunkeringID, Vessel, Port, DateTimeGMT, Supplier, HSFO, PriceHSFO, LSFO
                                  FROM [Bunkerings] WHERE Vessel = '<%= cboVessels.VesselName %>'"

THE ABOVE IS WHERE I NEED TO VALUE OF THE COMBOBOX

                    UpdateCommand="UPDATE [Bunkerings] SET Supplier = @Supplier, HSFO = @HSFO, PriceHSFO = @PriceHSFO, LSFO = @LSFO
                                   WHERE BunkeringID = @BunkeringID ">
                    <UpdateParameters>
                        <asp:Parameter Name="BunkeringID" Type="String" />
                        <asp:Parameter Name="Supplier" Type="String" />
                        <asp:Parameter Name="HSFO" Type="Decimal" />
                        <asp:Parameter Name="PriceHSFO" Type="Decimal" />
                        <asp:Parameter Name="LSFO" Type="Decimal" />
                    </UpdateParameters>
                </asp:SqlDataSource>
0
Comment
Question by:mark_norge
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
Faheem Shaikh earned 1500 total points
ID: 24185111
Refer to the attached code snippet.

<%@ Page Language="VB" %>
<html>
  <head runat="server">
    <title>Filtering Data In A GridView Using a DropDownList</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <b>Choose a state:</b>
      <asp:DropDownList ID="DropDownList1" DataSourceID="SqlDataSource2" AutoPostBack="true"
        DataTextField="state" Runat="server" />
      <asp:SqlDataSource ID="SqlDataSource2" Runat="server" SelectCommand="SELECT DISTINCT [state] FROM [authors]"
        ConnectionString="<%$ ConnectionStrings:Pubs %>" />
      <br />
      <br />
      <asp:GridView ID="GridView1" AllowSorting="True" AllowPaging="True" Runat="server"
        DataSourceID="SqlDataSource1" AutoGenerateEditButton="True" DataKeyNames="au_id"
        AutoGenerateColumns="False">
        <Columns>
          <asp:BoundField ReadOnly="true" HeaderText="ID" DataField="au_id" SortExpression="au_id" />
          <asp:BoundField HeaderText="Last Name" DataField="au_lname" SortExpression="au_lname" />
          <asp:BoundField HeaderText="First Name" DataField="au_fname" SortExpression="au_fname" />
          <asp:BoundField HeaderText="Phone" DataField="phone" SortExpression="phone" />
          <asp:BoundField HeaderText="Address" DataField="address" SortExpression="address" />
          <asp:BoundField HeaderText="City" DataField="city" SortExpression="city" />
          <asp:BoundField HeaderText="State" DataField="state" SortExpression="state" />
          <asp:BoundField HeaderText="Zip Code" DataField="zip" SortExpression="zip" />
          <asp:CheckBoxField HeaderText="Contract" SortExpression="contract" DataField="contract" />
        </Columns>
      </asp:GridView>
      <asp:SqlDataSource ID="SqlDataSource1" Runat="server" SelectCommand="SELECT [au_id], [au_lname], [au_fname], [phone], [address], [city], [state], [zip], [contract] FROM [authors] WHERE [state] = @state"
        UpdateCommand="UPDATE [authors] SET [au_lname] = @au_lname, [au_fname] = @au_fname, [phone] = @phone, [address] = @address, [city] = @city, [state] = @state, [zip] = @zip, [contract] = @contract WHERE [au_id] = @au_id"
        ConnectionString="<%$ ConnectionStrings:Pubs %>">
        <SelectParameters>
          <asp:ControlParameter Name="state" ControlID="DropDownList1" />
        </SelectParameters>
        <UpdateParameters>
          <asp:Parameter Name="au_lname" />
          <asp:Parameter Name="au_fname" />
          <asp:Parameter Name="phone" />
          <asp:Parameter Name="address" />
          <asp:Parameter Name="city" />
          <asp:Parameter Name="state" />
          <asp:Parameter Name="zip" />
          <asp:Parameter Name="contract" />
          <asp:Parameter Name="au_id" />
        </UpdateParameters>        
      </asp:SqlDataSource>
    </form>
  </body>
</html>

Open in new window

0
 

Author Comment

by:mark_norge
ID: 24185625
Faheem,

Thanks for the reply. I changed my code, however I have an issue. It looks like the "selectparameter" is not able to get the value of the combobox. If I use a defaultvalue it does work. Do you know what needs to be changed?

Best regards, MB

COMBOBOX

<td style="height: 20px; vertical-align: top;">
                <telerik:RadComboBox
                    ID="cboVessels"
                    Runat="server"
                    AutoPostBack="True"
                    DataSourceID="VesselsDataSource"
                    DataTextField="VesselName"
                    MarkFirstMatch="True">
                    <CollapseAnimation
                        type="OutQuint"
                        duration="200">
                    </CollapseAnimation>
                </telerik:RadComboBox>
            </td>

DATASOURCES

<asp:SqlDataSource
                    ID="BunkeringDataSource"
                    runat="server"
                    ConnectionString="<%$ ConnectionStrings:Connection %>"
                    SelectCommand="SELECT [BunkeringID], [Vessel], [Port], [DateTimeGMT], [Supplier], [HSFO], [PriceHSFO], [LSFO]
                                   FROM [Bunkerings] WHERE [Vessel] = @VesselName "
                    UpdateCommand="UPDATE [Bunkerings] SET [Supplier] = @Supplier, [HSFO] = @HSFO, [PriceHSFO] = @PriceHSFO, [LSFO] = @LSFO
                                   WHERE [BunkeringID] = @BunkeringID ">
                    <SelectParameters>
                        <asp:ControlParameter Name="VesselName" ControlID="cboVessels" Type="String" />
                    </SelectParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="BunkeringID" Type="String" />
                        <asp:Parameter Name="Supplier" Type="String" />
                        <asp:Parameter Name="HSFO" Type="Decimal" />
                        <asp:Parameter Name="PriceHSFO" Type="Decimal" />
                        <asp:Parameter Name="LSFO" Type="Decimal" />
                    </UpdateParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource
                    ID="VesselsDataSource"
                    Runat="server"
                    ConnectionString="<%$ ConnectionStrings:Connection %>"
                    SelectCommand="SELECT [VesselName] FROM [Vessels] WHERE [Status]='10' ORDER BY [VesselName] ASC">
                </asp:SqlDataSource>
0
 
LVL 8

Expert Comment

by:Faheem Shaikh
ID: 24185687
It looks good to me. Are you getting some error? can you paste it here?
0
 

Author Comment

by:mark_norge
ID: 24185789
Hi Faheem,

The thing is that I do not get any error message. However I also do not get any records in the grid. Since default value works the sql query to fill the grid seems ok. It seems the selected value is not passed (=empty). How can I check what the current value of the combobox is in aspx (I am normally using vb).

Regards, MB

0
 

Author Comment

by:mark_norge
ID: 24185820
Never mind Faheem,

I found it. In the SelectParameters the following needed to be added:
PropertyName ="text"

It now works,
Thanks for your help.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

840 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