如何在页面加载时使用gridview填充数据并在选择DDL时过滤? [英] How to have gridview to populate with data when page loads and filter when DDL has selection?

查看:54
本文介绍了如何在页面加载时使用gridview填充数据并在选择DDL时过滤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据绑定的GridView。在没有DDL就位的情况下,数据显示在GridView中。



这是GridView:



I have a GridView that is databound. The data shows in the GridView fine without the DDL inplace.

Here is the GridView:

<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:





Here is the SQL Data Source:

<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:





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:





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.



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.

推荐答案

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>
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:





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:





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>
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.



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.


Here is my solution:



Here is my solution:

<pre><asp:SqlDataSource ID="SqlDataSourceFiveYear" runat="server" 

                        ConnectionString="<%


这篇关于如何在页面加载时使用gridview填充数据并在选择DDL时过滤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆