Hi all I am using asp.net , C# ( VS2005) I fill dropdownlist using method defined in class on page load event it sucessfully fill the data in dropdownlist. as there is customer requirment to show different class of people in different color as well as tooltip of data. i succesffully managed to fill this with below shown code . but issue is when i fires other controls postback event. this dropdownlist loses its color as well as tooltip . Please suggest how to maintain the style of dropdownlist. code to fill dropdownlist public void Fillemp(DropDownList ctrl, string procedurename, string conn, SqlCommand cmd) { try { if (con == null) { this.openconnection(conn); this.con.Open(); // con.Open(); } if (con.State == ConnectionState.Closed) { this.openconnection(conn); con.Open(); } DataTable dtcompany = new DataTable(); ctrl.Items.Clear(); dtcompany = GetDataTable(procedurename, cmd); ctrl.Items.Add(new ListItem("Select One", "0")); ctrl.Items.Add(new ListItem("All" , "1")); ctrl.Items.Add(new ListItem("Self" , "2")); foreach (DataRow row in dtcompany.Rows) { ListItem item = new ListItem(row["emPname"].ToString(), row["er_emp_code"].ToString()); item.Attributes.Add("title", row["empname"].ToString()); int lvl = int.Parse(row["er_user_lvl"].ToString()); switch(lvl) { case 8: item.Attributes.Add("style", "color:green"); break; case 7: item.Attributes.Add("style", "color:blue"); break; case 6: item.Attributes.Add("style", "color:red"); break; case 5: item.Attributes.Add("style", "color:purple"); break; default : item.Attributes.Add("style", "color:BLACK"); break; } ctrl.Items.Add(item); } } catch (Exception ex) { throw ex; } finally { if (con != null) { con.Close(); } } }
page load event where i fill the dropdownlist if (!(IsPostBack)) { SqlCommand cmd = new SqlCommand(); cmd.Parameters.AddWithValue("empcode", Membership.GetUser().UserName); Doctor dr = new Doctor(); dr.Fillemp(Ddlzse, "SpGetPredecessor", "bbraunemisconnectstring", cmd); dr.FillctrlList1(Ddlsubdiv, "SPGETSUBDIV_GIVENEMP", "bbraunemisconnectstring", cmd, 0); }
and dropdownlist is defined as <TD id ="tdddlzsm" style="BORDER-BOTTOM: gray 1px solid; TEXT-ALIGN: left ; width: 490px;" align ="center" > <asp:DropDownList id="Ddlzse" runat="server" Width="480px" Font-Bold="False" Font-Size="9pt" Font-Names="Arial" AppendDataBoundItems="True" ></asp:DropDownList> </TD> <