C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Different Text Colors in DDL and Listbox


Posted Date: 19 Jan 2008    Resource Type: Code Snippets    Category: ADO.NET

Posted By: Mohan       Member Level: Gold
Rating:     Points: 10



This sample shows how to use CSS to create conditional item coloring with DropDownLists and ListBoxes (ASP.Net controls). As you see, in order to show the code here, with a DropDownList and a Listbox, some code lines are doubled. Just use whichever one applies for your useage.



<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<script language="VB" Runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
Dim conn as SqlConnection
conn = New SqlConnection(ConfigurationManager.ConnectionStrings("YourCnString").ConnectionString)
Dim da as SqlDataAdapter
Dim ds as DataSet
da = New SqlDataAdapter("Select * from Products ", conn)
ds = New DataSet()
da.Fill(ds, "Products")
Dim i as Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
ddl1.Items.Add(New ListItem(String.Format("{0:c}",ds.Tables(0).Rows(i)("UnitPrice")), ds.Tables(0).Rows(i)("ProductID")))
List1.Items.Add(New ListItem(String.Format("{0:c}",ds.Tables(0).Rows(i)("UnitPrice")), ds.Tables(0).Rows(i)("ProductID")))
If ds.Tables(0).Rows(i)("UnitPrice") <= 20 Then
ddl1.Items(i).Attributes.Add("style", "color:red")
List1.Items(i).Attributes.Add("style", "color:red")
Else
ddl1.Items(i).Attributes.Add("style", "color:green")
List1.Items(i).Attributes.Add("style", "color:green")
End If
Next
End Sub
</script>
<html>
<head>
<meta name="GENERATOR" Content="ASP Express 5.0">
<title>Untitled</title>
</head>
<body>
<form id="form1" Runat="server">
<asp:DropDownList ID="DDL1" Runat="Server" ></asp:DropDownList>
<asp:ListBox ID="List1" Runat="Server" ></asp:ListBox>
</form>
</body>
</html>




Responses

Author: Chris Jones    28 Mar 2008Member Level: Bronze   Points : 0
Thanks Mohan


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Programatically set or change DataRowState
Previous Resource: Assigning values for Null values in sql server
Return to Discussion Resource Index
Post New Resource
Category: ADO.NET


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing

Contact Us    Privacy Policy    Terms Of Use