Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a GridView that is databound. The data shows in the GridView fine without the DDL inplace.

Here is the GridView:

ASP.NET
<pre><asp:GridView ID="GridView5" runat="server" AllowPaging="True" 
                        AutoGenerateColumns="False" CellPadding="4" 
                        DataSourceID="SqlDataSourceFiveYear" ForeColor="#333333" GridLines="None" 
                        style="text-align: center" Width="994px">
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        <Columns>
                            <asp:BoundField DataField="INST_ID" HeaderText="INST_ID" 
                                SortExpression="INST_ID" />
                            <asp:BoundField DataField="SHORTNAME" HeaderText="SHORTNAME" 
                                SortExpression="SHORTNAME" />
                            <asp:BoundField DataField="FTE2013" HeaderText="FTE2013" 
                                SortExpression="FTE2013" />
                            <asp:BoundField DataField="FTE2014" HeaderText="FTE2014" 
                                SortExpression="FTE2014" />
                            <asp:BoundField DataField="FTE2015" HeaderText="FTE2015" 
                                SortExpression="FTE2015" />
                            <asp:BoundField DataField="FTE2016" HeaderText="FTE2016" 
                                SortExpression="FTE2016" />
                            <asp:BoundField DataField="FTE2017" HeaderText="FTE2017" 
                                SortExpression="FTE2017" />
                            <asp:BoundField DataField="HC2013" HeaderText="HC2013" 
                                SortExpression="HC2013" />
                            <asp:BoundField DataField="HC2014" HeaderText="HC2014" 
                                SortExpression="HC2014" />
                            <asp:BoundField DataField="HC2015" HeaderText="HC2015" 
                                SortExpression="HC2015" />
                            <asp:BoundField DataField="HC2016" HeaderText="HC2016" 
                                SortExpression="HC2016" />
                            <asp:BoundField DataField="HC2017" HeaderText="HC2017" 
                                SortExpression="HC2017" />
                        </Columns>
                        <EditRowStyle BackColor="#999999" />
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <SortedAscendingCellStyle BackColor="#E9E7E2" />
                        <SortedAscendingHeaderStyle BackColor="#506C8C" />
                        <SortedDescendingCellStyle BackColor="#FFFDF8" />
                        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                    </asp:GridView>


Here is the SQL Data Source:

ASP.NET
<pre><asp:SqlDataSource ID="SqlDataSourceFiveYear" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:HotSpotConnectionString %>" 
                        SelectCommand="SELECT * FROM [FTE2018Total] WHERE ([INST_ID] = @INST_ID) ORDER BY [INST_ID]">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="DropDownList1" Name="INST_ID" 
                                PropertyName="SelectedValue" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>


Here is the DDL:

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="DropDownDataSource" 
                    DataTextField="SHORTNM" DataValueField="INST_ID" AppendDataBoundItems="True"
                        style="font-weight: 700" Width="500px">
                        <asp:ListItem Text="All Institutions" Value="0" />
                    </asp:DropDownList>


Here is the DDL SQL Data Source:

<asp:SqlDataSource ID="DropDownDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:HotSpotConnectionString %>"
    SelectCommand="SELECT [INST_ID], [SHORTNM] FROM [TableCOCINST] ORDER BY [INST_ID]"></asp:SqlDataSource>


When the page loads it shows the DDL with All Institutions Selected as the first item but no GridView showing all the Data. When I make the selection in the DDL only that data is shown. Which is good but I am trying to get all the Data to show in the Gridview before the DDL selects an item.

What am i missing? Is my value for the DDL wrong?

What I have tried:

I have tried to change the way the DDL value.
Posted
Updated 6-Mar-18 6:39am

1 solution

Here is my solution:

ASP.NET
<pre><asp:SqlDataSource ID="SqlDataSourceFiveYear" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:HotSpotConnectionString %>" 
                        
                        SelectCommand="SELECT [INST_ID], [SHORTNAME], [FTE2013], [FTE2014], [FTE2015], [FTE2016], [FTE2017], [HC2013], [HC2014], [HC2015], [HC2016], [HC2017] FROM [FTE2018Total] ORDER BY [INST_ID]" 
                        FilterExpression="INST_ID = '{0}'">
                        <FilterParameters>
                        <asp:ControlParameter Name="INST_ID" ControlID="DropDownList1" PropertyName="SelectedValue" />
                        </FilterParameters>
                    </asp:SqlDataSource>



This code was edited at the GridView SQL Data Source.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900