473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DropDownList Box Post Back

Hi - using VS2005, VB.NET, ASP.NET 2.0, Program is server-client using IE6

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
  1.  Public Shared Function Populate_Employees_ListBox(ByVal strConnection As String, ByRef ddl As DropDownList, ByVal strSproc As String) As Integer
  2.         Dim ds As DataSet
  3.         Dim lt As ListItem
  4.         Dim count As Integer = 0
  5.         Dim index As Integer = 0
  6.         Dim pi As Byte
  7.         Dim ac As Byte
  8.         Try
  9.             Using objEmployee As New CVSBusinessLogic.CVSBLEmployees(strConnection)
  10.                 ds = objEmployee.GetEmployees(strSproc)
  11.                 count = objEmployee.Get_Number_of_Rows_in_Employee_Dataset(ds)
  12.                  While index < count
  13.                         lt = New ListItem
  14.                         lt.Text = CType(objEmployee.Get_Employees_Item(ds, index, "EmployeeName", "EmployeeFirstName"), String)
  15.                         lt.Value = objEmployee.Get_Employees_Item(ds, index, "EmployeeRefID").ToString  ' Gets a Guid converted to string
  16.                         pi = CType(objEmployee.Get_Employees_Item(ds, index, "PendingInclusion", String.Empty), Byte)
  17.                         ac = CType(objEmployee.Get_Employees_Item(ds, index, "IsActive", String.Empty), Byte)
  18.                         If pi = 0 And ac = 1 Then
  19.                             lt.Attributes.Add("style", "background-color: White")
  20.                         ElseIf pi = 1 Then
  21.                             lt.Attributes.Add("style", "background-color: #BFE2F9")
  22.                         ElseIf ac = 0 Then
  23.                             lt.Attributes.Add("style", "background-color: #FFF99D")
  24.                         End If
  25.                         ddl.Items.Add(lt)
  26.                         index += 1
  27.                     End While
  28.                 End Using
  29.         Catch ExceptionErr As Exception
  30.             Throw New System.Exception(ExceptionErr.Message, ExceptionErr.InnerException)
  31.         Finally
  32.             Populate_Employees_ListBox = count
  33.         End Try
  34.     End Function
  35.  
The values of 'pi' and 'ac' are got from the dataset and used to set the background color of the listitem which is then added to the DDL. This code is called from the Page_Load event and works fine. However when the page is posted back (for whatever reason) the DDL colors are not there - although everything else is fine. EnableViewState for the DDL is set True in the Web Page.

Can somebody please help ?
Jul 7 '11 #1
0 1052

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Lolam | last post by:
Here is my problem, I am using 3 user controls in a page(Test.aspx) which are 1.Header UC 2.Body UC 3.Footer UC HeaderUC has a DropDownList control named "ddlList". On SelectIndexChanged...
3
by: Brian Henry | last post by:
I have two list boxes on my form... lstCanSend and lstRecipients... well then there are two buttons add and remove between them (your basic select and pick listing) which uses java script to move...
0
by: jonathanyan | last post by:
Hi all: I am dynamically creating two dropdownlist controls in a user control, the data of the second dropdownlist control depends on the selected value of the first dropdownlist control, the...
2
by: sunilthk | last post by:
Hi All, I have a question. If javascript is disabled how asp.net determines which control has caused the post back. As we know that when we clicks on the button the buttons name goes with posted...
12
by: Michael Lang | last post by:
I'm adding checkbox controls to a panel in a post back, I then have a second post back in which I attempt to process the checkbox controls however they seem to have disappeared off the panel. The...
2
by: Garg | last post by:
I had a listbox, whose autoPostBAck property was set to true. So. if I was clicking on any item for the first time, it caused a successful post-back. However, if i clicked on the item...
1
by: =?Utf-8?B?Z29yaWxsYQ==?= | last post by:
As we know , the view state is not responsible for having TextBoxes, CheckBoxes, DropDownLists, and other Web controls remember their values across postback. When I dynamically add a...
1
by: mark4asp | last post by:
How can I stop a post back from firing when there is no need for it to? I have a GridView pager template (shown below): There are 3 commands: ddlPager_SelectedIndexChanged - move the page to...
0
by: cmrhema | last post by:
Hi, I populate two dropdownlist in asp.net. Both are assigned to a required field validator. The codebehind is as below if (!Page.IsPostBack) { DataTable dt = new...
1
by: muthukumaran08 | last post by:
I have textboxes and dropdownlist on my page. And i have image button when i click this image button i m validating textboxes on javascript and if it returns true, i need to do a post back to save...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.