Solved

Display Data Grid based on dropdown list selection

Posted on 2007-11-19
3
1,097 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

816 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

10 Experts available now in Live!

Get 1:1 Help Now