Solved

Display Data Grid based on dropdown list selection

Posted on 2007-11-19
3
1,114 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…

734 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