color of Drop down list remove on post back...
-
I uses the following code to dynamic fill the dropdownlist and forecolor of list item is set, it show good when first time load, but the style removes when the page postback...Any suggestion? The code i use to fill dropdownlist is following... Try cnn.Open() myreader = cmd.ExecuteReader() While myreader.Read() lst = New ListItem(myreader.GetValue(0).ToString().Trim(), myreader.GetValue(1).ToString().Trim()) If myreader.GetValue(2).ToString().Trim() = 0 Then lst.Attributes.Add("style", "color:Red") Else lst.Attributes.Add("style", "color:Green") End If ddl.Items.Add(lst) End While ddl.DataBind() Catch ex As Exception Throw New Exception(ex.Message) Finally cnn.Close() End Try
The miracle is this--the more we share, the more we have.
-
I uses the following code to dynamic fill the dropdownlist and forecolor of list item is set, it show good when first time load, but the style removes when the page postback...Any suggestion? The code i use to fill dropdownlist is following... Try cnn.Open() myreader = cmd.ExecuteReader() While myreader.Read() lst = New ListItem(myreader.GetValue(0).ToString().Trim(), myreader.GetValue(1).ToString().Trim()) If myreader.GetValue(2).ToString().Trim() = 0 Then lst.Attributes.Add("style", "color:Red") Else lst.Attributes.Add("style", "color:Green") End If ddl.Items.Add(lst) End While ddl.DataBind() Catch ex As Exception Throw New Exception(ex.Message) Finally cnn.Close() End Try
The miracle is this--the more we share, the more we have.
Why dont you apply the style again... Use if(IsPostBack) ddl.Style.Add(HtmlTextWriterStyle.Color,"red") :thumbsup:
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
Why dont you apply the style again... Use if(IsPostBack) ddl.Style.Add(HtmlTextWriterStyle.Color,"red") :thumbsup:
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
I applid color based on the flag if the flag value in database =0 then the item color will red and if flag value is 1 then item color will green?...
The miracle is this--the more we share, the more we have.
-
I applid color based on the flag if the flag value in database =0 then the item color will red and if flag value is 1 then item color will green?...
The miracle is this--the more we share, the more we have.
yes .. then why dont you set the Database flag again during postback, and do set style accordingly.
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.