从下拉列表中选择项目后,不会加载DataGridView [英] DataGridView does not load after selecting item from drop down list

查看:87
本文介绍了从下拉列表中选择项目后,不会加载DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到sql数据库的下拉列表,并在数据网格视图中显示所选数据。



但是当我在drop上选择一个项目时下来列表它只加载但不显示选择项目/项目



任何一个有帮助的人会欣赏



还是学习者



这是我的代码:



ASP.NET代码



I have a drop down list which connect to sql database and display the selected data in a data grid view.

But when I select an item on the drop down list it only load but does not display the select item/items

Any one with help would appreciate that

Still a learner

Here is my codes :

ASP.NET Code

<table>
    <tr>
        <td align="left"><asp:Label id="lblShow" Text="Select Perway Status : " Font-Bold="true" runat="server"></asp:Label>
            <asp:DropDownList ID="ddlShow" runat="server" DataSourceID="SqlDataSource3"

                DataTextField="Perway_Status" DataValueField="Perway_Status" AutoPostBack="true"

                onselectedindexchanged="ddlShow_SelectedIndexChanged" >
                <asp:ListItem Text="All" Value="All" Selected="True"  Enabled="True" />
            </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource3" runat="server"

                        ConnectionString="<%$ ConnectionStrings:DropDownListConnectionString %>"

                        SelectCommand="SELECT TOP 9 Station_Status_Current.Status_Time, Stations.Station_Name, Stations.Station_Lines, Sections.Section_Name, Sections.Perway_Status, Sections.Equipment_Status FROM Station_Status_Current INNER JOIN Stations ON Station_Status_Current.Station_ID = Stations.Station_ID CROSS JOIN Sections CROSS JOIN Status_Legend">
                    </asp:SqlDataSource>
        </td>
    </tr>
  </table>


                     <asp:SqlDataSource ID="SqlDataSource1" runat="server"

                        ConnectionString="<%$ ConnectionStrings:StatStressConnectionString2 %>"

                        SelectCommand="SELECT TOP 9 Station_Status_Current.Status_Time, Stations.Station_Name, Stations.Station_Lines, Sections.Section_Name, Sections.Perway_Status, Sections.Equipment_Status FROM Station_Status_Current INNER JOIN Stations ON Station_Status_Current.Station_ID = Stations.Station_ID CROSS JOIN Sections CROSS JOIN Status_Legend">
                    </asp:SqlDataSource>
    <asp:GridView ID="gvShowAll" runat="server" AutoGenerateColumns="False"

                        HorizontalAlign="Center" CellPadding="5" PageSize="20" AllowPaging="True" DataSourceID="SqlDataSource1">
        <Columns>
            <asp:BoundField DataField="Status_Time" HeaderText="Status Time"

                SortExpression="Status_Time" />
            <asp:BoundField DataField="Section_Name" HeaderText="Section Name"

                SortExpression="Section_Name" />
            <asp:BoundField DataField="Perway_Status" HeaderText="Perway Status"

                SortExpression="Perway_Status" />
            <asp:BoundField DataField="Equipment_Status" HeaderText="Equipment Status"

                SortExpression="Equipment_Status" />
            <asp:BoundField DataField="Station_Name" HeaderText="Station Name"

                SortExpression="Station_Name" />
            <asp:BoundField DataField="Station_Lines" HeaderText="Station Lines"

                SortExpression="Station_Lines" />
        </Columns>
    </asp:GridView>

</asp:Content>







C#背后的代码:






Code Behind C#:

protected void ddlShow_SelectedIndexChanged(object sender, EventArgs e)
       {
           SqlDataSource3.DataBind();
           gvShowAll.DataBind();
       }
       public override void VerifyRenderingInServerForm(Control control)
       {
           return;
       }





提前致谢



Thanks in advance

推荐答案

ConnectionStrings: DropDownListConnectionString %>

< span class =code-attribute> SelectCommand = SELECT TOP 9 Station_Status_Current.Status_Time,Stations.Station_Name,Stations.Station_Lines,Sections.Section_Name,Sections.Perway_Status,Sections.Equipment_Status FROM Station_Status_Current INNER JOIN Stations ON Station_Status_Current.Station_ID = Stations.Station_ID CROSS JOIN部分CROSS JOIN Status_Legend >
< / asp:SqlDataSource >
< / td >
< < /秒pan> / tr >
< / table >


< asp:SqlDataSource ID = SqlDataSource1 runat = server

ConnectionString = <%
ConnectionStrings:DropDownListConnectionString %>" SelectCommand="SELECT TOP 9 Station_Status_Current.Status_Time, Stations.Station_Name, Stations.Station_Lines, Sections.Section_Name, Sections.Perway_Status, Sections.Equipment_Status FROM Station_Status_Current INNER JOIN Stations ON Station_Status_Current.Station_ID = Stations.Station_ID CROSS JOIN Sections CROSS JOIN Status_Legend"> </asp:SqlDataSource> </td> </tr> </table> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%


ConnectionStrings:StatStressConnectionString2 %>

< span class =code-attribute> SelectCommand = SELECT TOP 9 Station_Status_Current.Status_Time,Stations.Station_Name,Stations.Station_Lines,Sections.Section_Name,Sections.Perway_Status,Sections.Equipment_Status FROM Station_Status_Current INNER JOIN Stations ON Station_Status_Current.Station_ID = Stations.Station_ID CROSS JOIN Section CROSS JOIN Status_Legend >
< / asp:SqlDataSource >
< asp:GridView ID = gvShowAll runat = server AutoGenerateColumns = False

HorizontalAlign=\"Center\" CellPadding=\"5\" PageSize=\"20\" AllowPaging=\"True\" DataSourceID=\"SqlDataSource1\">
<Columns>
<asp:BoundField DataField=\"Status_Time\" HeaderText=\"Status Time\"

SortExpression=\"Status_Time\" />
<asp:BoundField DataField=\"Section_Name\" HeaderText=\"Section Name\"

SortExpression=\"Section_Name\" />
<asp:BoundField DataField=\"P erway_Status\" HeaderText=\"Perway Status\"

SortExpression=\"Perway_Status\" />
<asp:BoundField DataField=\"Equipment_Status\" HeaderText=\"Equipment Status\"

SortExpression=\"Equipment_Status\" />
<asp:BoundField DataField=\"Station_Name\" HeaderText=\"Station Name\"

SortExpression=\"Station_Name\" />
<asp:BoundField DataField=\"Station_Lines\" HeaderText=\"Station Lines\"

SortExpressio n=\"Station_Lines\" />
</Columns>
</asp:GridView>

</asp:Content>
ConnectionStrings:StatStressConnectionString2 %>" SelectCommand="SELECT TOP 9 Station_Status_Current.Status_Time, Stations.Station_Name, Stations.Station_Lines, Sections.Section_Name, Sections.Perway_Status, Sections.Equipment_Status FROM Station_Status_Current INNER JOIN Stations ON Station_Status_Current.Station_ID = Stations.Station_ID CROSS JOIN Sections CROSS JOIN Status_Legend"> </asp:SqlDataSource> <asp:GridView ID="gvShowAll" runat="server" AutoGenerateColumns="False" HorizontalAlign="Center" CellPadding="5" PageSize="20" AllowPaging="True" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="Status_Time" HeaderText="Status Time" SortExpression="Status_Time" /> <asp:BoundField DataField="Section_Name" HeaderText="Section Name" SortExpression="Section_Name" /> <asp:BoundField DataField="Perway_Status" HeaderText="Perway Status" SortExpression="Perway_Status" /> <asp:BoundField DataField="Equipment_Status" HeaderText="Equipment Status" SortExpression="Equipment_Status" /> <asp:BoundField DataField="Station_Name" HeaderText="Station Name" SortExpression="Station_Name" /> <asp:BoundField DataField="Station_Lines" HeaderText="Station Lines" SortExpression="Station_Lines" /> </Columns> </asp:GridView> </asp:Content>







Code Behind C#:






Code Behind C#:

protected void ddlShow_SelectedIndexChanged(object sender, EventArgs e)
       {
           SqlDataSource3.DataBind();
           gvShowAll.DataBind();
       }
       public override void VerifyRenderingInServerForm(Control control)
       {
           return;
       }





Thanks in advance



Thanks in advance


Try this:

Try this:
protected void ddlShow_SelectedIndexChanged(object sender, EventArgs e)
       {
           gvShowAll.DataSource = SqlDataSource3; 
           gvShowAll.DataBind();
       }
       public override void VerifyRenderingInServerForm(Control control)
       {
           return;
       }


这篇关于从下拉列表中选择项目后,不会加载DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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