I have a asp dropdown list box which I need to populate from a dataset returned from a SQL query. I need to change the background color of each list item according to two items in the dataset. Am using a generic function in a VB code behind as follows : It uses some functions in a DLL (CVSBusinessLogic) which are hopefully self-explanatory and are not the issue.
Expand|Select|Wrap|Line Numbers
- Public Shared Function Populate_Employees_ListBox(ByVal strConnection As String, ByRef ddl As DropDownList, ByVal strSproc As String) As Integer
- Dim ds As DataSet
- Dim lt As ListItem
- Dim count As Integer = 0
- Dim index As Integer = 0
- Dim pi As Byte
- Dim ac As Byte
- Try
- Using objEmployee As New CVSBusinessLogic.CVSBLEmployees(strConnection)
- ds = objEmployee.GetEmployees(strSproc)
- count = objEmployee.Get_Number_of_Rows_in_Employee_Dataset(ds)
- While index < count
- lt = New ListItem
- lt.Text = CType(objEmployee.Get_Employees_Item(ds, index, "EmployeeName", "EmployeeFirstName"), String)
- lt.Value = objEmployee.Get_Employees_Item(ds, index, "EmployeeRefID").ToString ' Gets a Guid converted to string
- pi = CType(objEmployee.Get_Employees_Item(ds, index, "PendingInclusion", String.Empty), Byte)
- ac = CType(objEmployee.Get_Employees_Item(ds, index, "IsActive", String.Empty), Byte)
- If pi = 0 And ac = 1 Then
- lt.Attributes.Add("style", "background-color: White")
- ElseIf pi = 1 Then
- lt.Attributes.Add("style", "background-color: #BFE2F9")
- ElseIf ac = 0 Then
- lt.Attributes.Add("style", "background-color: #FFF99D")
- End If
- ddl.Items.Add(lt)
- index += 1
- End While
- End Using
- Catch ExceptionErr As Exception
- Throw New System.Exception(ExceptionErr.Message, ExceptionErr.InnerException)
- Finally
- Populate_Employees_ListBox = count
- End Try
- End Function
Can somebody please help ?