Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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



Code Behind C#:

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


Thanks in advance
Posted

1 solution

Try this:
C#
protected void ddlShow_SelectedIndexChanged(object sender, EventArgs e)
       {
           gvShowAll.DataSource = SqlDataSource3; 
           gvShowAll.DataBind();
       }
       public override void VerifyRenderingInServerForm(Control control)
       {
           return;
       }
 
Share this answer
 
Comments
Puseletso Michelle 14-Mar-14 4:10am    
hiits not helping am getting an error : "Both DataSource & DataSourceID are defined on gvShowAll.Remove One definition"
Puseletso Michelle 14-Mar-14 4:49am    
thanks,that works fine just need to change my sql statement to display the selected items.....
Tom Marvolo Riddle 14-Mar-14 4:50am    
You're very welcome!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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