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
Solved

Display Data Grid based on dropdown list selection

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Title # Comments Views Activity
Why does my excel data start at B1 instead of A1. 9 91
asp enable view state 1 28
IEnumerable<T> to a List<T> 8 37
How to use NFS (Network File System) in Asp.net mvc 5? 4 43
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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…

856 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