Solved

Display Data Grid based on dropdown list selection

Posted on 2007-11-19
3
1,087 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
Comment Utility
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
Comment Utility
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
Comment Utility
You were both right on.  I made a mistake with the binding control.  Thank you for your help.

John
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

9 Experts available now in Live!

Get 1:1 Help Now