So far, everything loads without errors, and SQL calls will be replaced by more secure stored procedures when everything works. When I select a furnace from the drop-down menu, it should go to the method and fill in the text box with the run number. But when I choose something, it only returns to the first index 10A. I also coded that index 0 should say “Select Furnace”, but that also does not appear, but only the first index. Are there any suggestions on how to grab the selected index and populate the text box from the SQL query?
<asp:Content ID="BodyContent" ContentPlaceHolderID="BodyPlaceHolder" runat="server">
<center>
<table style="text-align:left">
<tr>
<td align="right">
<asp:Label ID="FurnaceID" Text="JUMP TO FURNACE : " runat="server" />
</td>
<td></td>
<td>
<asp:DropDownList ID="FurnID" runat="server" AutoPostBack ="true"
onselectedindexchanged="FurnID_SelectedIndexChanged" Width="150px">
<asp:ListItem Text="Select Furnace" Value = "0" />
</asp:DropDownList>
Behind the code:
LoadList (); called in the page_load event
public void LoadList()
{
SqlCommand cmd = new SqlCommand("SELECT * FROM [Furnace]", new SqlConnection(ConfigurationManager.ConnectionStrings["FurnaceDeckConnectionString"].ConnectionString));
cmd.Connection.Open();
SqlDataReader Furns;
Furns = cmd.ExecuteReader();
FurnID.DataSource = Furns;
FurnID.DataValueField = "Furnaceno";
FurnID.DataTextField = "Furnaceno";
FurnID.DataBind();
cmd.Connection.Close();
cmd.Connection.Dispose();
}
When the index changes, this method is called:
protected void FurnID_SelectedIndexChanged(object sender, EventArgs e)
{
if (IsPostBack)
{
String selectedFurn = "";
ListItem selectFurn = FurnID.Items.FindByText(selectedFurn);
LoadFurnDetails(selectedFurn);
}
}
public void LoadFurnDetails(String F)
{
String selectF = F;
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand("SELECT * FROM [Furnace Run Data Table] Where Furnace = 'selectF' and Completed = 0 ", new SqlConnection(ConfigurationManager.ConnectionStrings["FurnaceDeckConnectionString"].ConnectionString));
cmd.Connection.Open();
SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
lblFurnId.Text = dt.Rows[0]["runno"].ToString();
}
cmd.Connection.Close();
cmd.Connection.Dispose();
}