DisarmedDevo DisarmedDevo - 3 months ago 15
C# Question

If statement is not triggering the event

So I am working in ASP.net for the first time so I do not know if it is the if statement that is broken or if there is something weird between client server that I do not understand yet.... Below will be my server side and client side code. I have my code writing to a log file so I know that I have the correct syntax in my If statement. What this program does so far is that there are two drop down list the selection from the first will determine what is in the second. Using hard coded values for test first before switching it to a SQL datatable. Right now I select the first value and nothing happens. Any help figuring out what is not working with this is appreciated.

Server Side

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FIS_DashBoard_Web.cs;

namespace FIS_DashBoard_Web.www
{
public partial class PSBSecondary : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
Utils ut = new Utils();
protected void ddlLine_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlLine.SelectedItem.Equals("WSM2"))
{
ddlBuiltProduct.Items.Add("GFE Control Board");
}
ut.WriteToLog(ddlLine.SelectedItem.ToString());
}
}

}


Client Side

<div style="text-align: right;">
<asp:Table ID="Table2" runat="server">
<asp:TableRow>
<asp:TableHeaderCell Text="Line"/>
<asp:TableCell>
<asp:DropDownList ID="ddlLine" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlLine_SelectedIndexChanged">
<asp:ListItem Value="WSM1" Text="WSM1"/>
<asp:ListItem Value="WSM2" Text="WSM2" />
<asp:ListItem Value="Pillarhouse 1" Text="Pillarhouse 1"/>
<asp:ListItem Value="Pillarhouse 2" Text="Pillarhouse 2"/>
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableHeaderCell Height="20" Text="What Product Was Built?"/>
<asp:TableCell>
<asp:DropDownList ID="ddlBuiltProduct" runat="server" AutoPostBack="true">

</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>

Answer

Use SelectedItem.Text

if (ddlLine.SelectedItem.Text.Equals("WSM2"))
{
  ddlBuiltProduct.Items.Add("GFE Control Board");
}
Comments