Puseletso Modikoe

Puseletso Modikoe

  • NA
  • 11
  • 2.3k

selecting an item from dropdownlist display in datagridview

Mar 25 2014 4:41 AM
How can I retrieve data from sql database by selecting an item from a drop down list and displaying the selected item information in a data grid view?

following is a code that I have but its not working I can select from a dropdown list but nothing appears in a data grid view

ASP.NET Code:

<


table>


      


<tr>


           


<td>


               


<asp:Label ID="lblShow" runat="server" Text="Select Station ID"></asp:Label>


               


<asp:DropDownList ID="ddlshow" runat="server" DataSourceID="SqlDataSource3"


                   


DataTextField="Perway_Status" DataValueField="Perway_Status"


                   


onselectedindexchanged="ddlshow_SelectedIndexChanged">


                   


<asp:ListItem Text="All" Value="All" Selected="True"/>


               


</asp:DropDownList>


               


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


                   


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


                   


                   


SelectCommand="SELECT DISTINCT Stations.Station_ID, Stations.Station_Name, Sections.Section_ID, Sections.Perway_Status, Sections.Equipment_Status, Station_Status_Current.Status_Time FROM Sections INNER JOIN Stations ON Sections.Section_ID = Stations.Section_ID CROSS JOIN Station_Status_Current CROSS JOIN Status_Legend ORDER BY Stations.Station_ID">


               


</asp:SqlDataSource>


           


</td>


          


      


</tr>


      


<tr>


           


<td>


               


<asp:GridView ID="GdvshowAll" runat="server" DataSourceID="SqlDataSource1"


                   


AutoGenerateColumns="False">


                   


<Columns>


                       


<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_ID" HeaderText="Station_ID"


                           


SortExpression="Station_ID" InsertVisible="False" ReadOnly="True" />


                       


<asp:BoundField DataField="Station_Lines" HeaderText="Station_Lines"


                           


SortExpression="Station_Lines" />


                       


<asp:BoundField DataField="Status_Time" HeaderText="Status_Time"


                           


SortExpression="Status_Time" />


                       


<asp:BoundField DataField="Station_Name" HeaderText="Station_Name"


                           


SortExpression="Station_Name" />


                   


</Columns>


               


</asp:GridView>


               


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


                   


ConnectionString="<%$ ConnectionStrings:StatStressConnectionString %>" SelectCommand=" SELECT DISTINCT


                         Sections.Section_Name, Sections.Perway_Status, Sections.Equipment_Status, Stations.Station_ID, Stations.Station_Lines,


                         Station_Status_Current.Status_Time, Stations.Station_Name


FROM            Sections LEFT OUTER JOIN


                         Stations ON Stations.Section_ID = Sections.Section_ID LEFT OUTER JOIN


                         Station_Status_Current ON Station_Status_Current.Station_ID = Stations.Station_ID AND Station_Status_Current.Station_ID = Stations.Section_ID


WHERE        (Stations.Station_ID = @ddlshow)


ORDER BY Stations.Station_ID ">


                   


<SelectParameters>


                       


<asp:ControlParameter ControlID="ddlshow" Name="ddlShow"


                           


PropertyName="SelectedValue" />



</SelectParameters>


</asp:SqlDataSource>


</td>


</tr>


</

table> 

C# Code:

protected



void ddlshow_SelectedIndexChanged(object sender, EventArgs e)


        {


            SqlDataSource1.DataBind();


            GdvshowAll.DataBind();


        }



       


public override void VerifyRenderingInServerForm(Control control)


        {


           


return;


        }

                          




Answers (9)