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;
}

Abhay ShankerRank #375 · 6.7K reputationPosted Mar 25, 2014, 1:44 AM EDT
Modify Dropdownlist as below
<asp:DropDownList ID="ddlshow" runat="server" AutoPostBack="true" DataSourceID="SqlDataSource3" DataTextField="Perway_Status" DataValueField="Perway_Status" onselectedindexchanged="ddlshow_SelectedIndexChanged">
Munesh SharmaRank #174 · 13.9K reputationPosted Mar 25, 2014, 1:19 AM EDT
Drag and down a drop down list from toolbox and 3 text box for ID,name, and age. Make a function for getting database value (Name) in drop down list and after click at any name then show all detail of that respected persion.
Click on dropdown in write this code
{
string str = "server = MUNESH\\SQL2008R2;Database=datastore;UID=sa;Password=123;";
SqlConnection con = new SqlConnection(str);
string query = "select * from tablename where name = '"+dropdown1.text+"' ";
SqlCommand cmd = new SqlCommand( query,con);
sqldatareader dbr;
try
{
con.open();
dbr = cmd.executereader();
while(dbr.read())
{
string sID = (string) dbr["ID"].tostring;
string sname = (string) dbr["name"] // name is string value
string sage = (string) dbr["age"].tostring;
textbox1.text = sid;
textbox2.text = sname;
textbox3.text = sage;
}
catch(execption es)
{
messagebox.show(es.message);
}
}
}
This code will show selected value from drop down in textbox.
Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted Mar 25, 2014, 1:33 AM EDT
Puseletso Modikoe11 reputationPosted Mar 25, 2014, 1:34 AM EDT
Abhay ShankerRank #375 · 6.7K reputationPosted Mar 25, 2014, 1:34 AM EDT
Puseletso Modikoe11 reputationPosted Mar 25, 2014, 1:35 AM EDT
Puseletso Modikoe11 reputationPosted Mar 25, 2014, 1:39 AM EDT
Abhay ShankerRank #375 · 6.7K reputationPosted Mar 25, 2014, 1:46 AM EDT
Puseletso Modikoe11 reputationPosted Mar 25, 2014, 1:49 AM EDT