Postback Removing Styling from Page
- by Roy
Hi,
Currently I've created a ASP.Net page that has a dropdown control with autopostback set to true. I've also added color backgrounds for individual listitems. Whenever an item is selected in the dropdown control the styling is completely removed from all of the list items. How can I prevent this from happening? I need the postback to pull data based on the dropdown item that is selected. Here is my code.
aspx file:
<asp:DropDownList ID="EmpDropDown" AutoPostBack="True" OnSelectedIndexChanged="EmpDropDown_SelectedIndexChanged" runat="server">
</asp:DropDownList>
<asp:TextBox ID="MessageTextBox" TextMode="MultiLine" Width="550" Height="100px" runat="server"></asp:TextBox>
aspx.cs code behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetEmpList();
}
}
protected void EmpDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
GetEmpDetails();
}
private void GetEmpList()
{
SqlDataReader dr = ToolsLayer.GetEmpList();
int currentIndex = 0;
while (dr.Read())
{
EmpDropDown.Items.Add(new ListItem(dr["Title"].ToString(), dr["EmpKey"].ToString()));
if (dr["Status"].ToString() == "disabled")
{
EmpDropDown.Items[currentIndex].Attributes.Add("style", "background-color:red;");
}
currentIndex++;
}
dr.Close();
}
private void GetEmpDetails()
{
SqlDataReader dr = ToolsLayer.GetEmpDetails(EmpDropDown.SelectedValue);
while (dr.Read())
{
MessageTextBox.Text = dr["Message"].ToString();
}
dr.Close();
}
Thank You