Solved

Display Data Grid based on dropdown list selection

Posted on 2007-11-19
3
1,110 Views
Last Modified: 2010-04-21
Hello,

I have a dropdown list and need to display information in a grid based on the selection.  I can't get the thing working.  Here is the code:



Connection Strings:

<asp:SqlDataSource ID="SLSqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" oldValuesParameterFormatString="original_{0}" SelectCommand="SELECT DISTINCT PMFM.FirmName, SLHD.Description, SLHD.Job, SLHD.SL + '----' + PMFM.FirmName AS SLVendorName, SLHD.SL FROM         SLHD INNER JOIN PMFM ON SLHD.Vendor = PMFM.FirmNumber WHERE     (SLHD.Job = @Job ORDER BY SLVendorName">
<SelectParameters>
<asp:ControlParameter ControlID="ProjectDropDownList" Name="Job" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
 
<asp:SqlDataSource ID="InvoiceGVSqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" SelectCommand="SELECT SLHD.SL, SLCD.SLChangeOrder, SLHD.Vendor, SUM(SLCD.ChangeCurCost) AS Cost, udusSLChgSignDate.SignedDate FROM SLHD INNER JOIN SLCD ON SLHD.SL = SLCD.SL AND SLHD.SLCo = SLCD.SLCo LEFT OUTER JOIN udusSLChgSignDate ON SLCD.SL = udusSLChgSignDate.SL AND SLCD.SLCo = udusSLChgSignDate.Co AND SLCD.SLChangeOrder = udusSLChgSignDate.SLChangeOrder GROUP BY SLHD.SL, SLCD.SLChangeOrder, SLHD.Vendor, udusSLChgSignDate.SignedDate HAVING (SLHD.SL = @SL) AND (udusSLChgSignDate.SignedDate IS NULL OR (NOT (udusSLChgSignDate.SignedDate = CONVERT(DATETIME, '1955-05-05 00:00:00', 102))))">                            
<SelectParameters>
<asp:QueryStringParameter DefaultValue="" Name="SL" QueryStringField="SL" />
</SelectParameters>
</asp:SqlDataSource>


Dropdown list and Grid:

<asp:DropDownList ID="SLDrList" runat="server" OnDataBound="ddlSL_DataBound" CssClass="dataentry" DataSourceID="SLSqlDS" DataTextField="SLVendorName" DataValueField="SL" AutoPostBack="True" Visible="False" Width="335px">
</asp:DropDownList>

<asp:GridView ID="GVInvoice" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="True" DataSourceID="InvoiceGVSqlDS" EnableSortingAndPagingCallbacks="True" Width="330px" PageSize="5" Visible="True">
<Columns>
<asp:BoundField  DataField="SL" HeaderText="SL" SortExpression="SL" ItemStyle-VerticalAlign="Top" />
</Columns>
</asp:GridView>

Any help would be appreciated.

John
0
Comment
Question by:jcpatterson
3 Comments
 
LVL 37

Accepted Solution

by:
samtran0331 earned 350 total points
ID: 20315417
John,
Your gridview is bound to sqldatasource:
<asp:SqlDataSource ID="InvoiceGVSqlDS"

and the select parameter is looking for a querystring parameter, not the dropdownlist, change that select parameter to a control parameter like you have in:
<asp:SqlDataSource ID="SLSqlDS"

....or is the grid supposed to be bound to:
<asp:SqlDataSource ID="SLSqlDS"?
0
 
LVL 16

Assisted Solution

by:GreymanMSC
GreymanMSC earned 150 total points
ID: 20316302
Why are you using a QueryString parameter in the GridView's SQLDataSource?   It looks as though you
wish to select the @SL parameter using the DropDownList.   A ControlParameter would seem more appropriate.
<asp:SqlDataSource ID="InvoiceGVSqlDS" runat="server"
 ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
 SelectCommand="SELECT SLHD.SL, SLCD.SLChangeOrder, SLHD.Vendor, SUM(SLCD.ChangeCurCost) AS Cost, udusSLChgSignDate.SignedDate FROM SLHD INNER JOIN SLCD ON SLHD.SL = SLCD.SL AND SLHD.SLCo = SLCD.SLCo LEFT OUTER JOIN udusSLChgSignDate ON SLCD.SL = udusSLChgSignDate.SL AND SLCD.SLCo = udusSLChgSignDate.Co AND SLCD.SLChangeOrder = udusSLChgSignDate.SLChangeOrder GROUP BY SLHD.SL, SLCD.SLChangeOrder, SLHD.Vendor, udusSLChgSignDate.SignedDate HAVING (SLHD.SL = @SL) AND (udusSLChgSignDate.SignedDate IS NULL OR (NOT (udusSLChgSignDate.SignedDate = CONVERT(DATETIME, '1955-05-05 00:00:00', 102))))">                             
  <SelectParameters>
    <asp:ControlParameter ControlID="SLDrList" Name="SL" PropertyName="SelectedValue" Type="String" />
  </SelectParameters>
</asp:SqlDataSource>

Open in new window

0
 
LVL 1

Author Closing Comment

by:jcpatterson
ID: 31410012
You were both right on.  I made a mistake with the binding control.  Thank you for your help.

John
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FInd Image Control Gridview 3 34
C# MVC Insert Multiple Row into DB 2 60
Where is this file? 3 32
Running powershell scripts from ASP.NET 6 54
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

685 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