473,402 Members | 2,046 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,402 software developers and data experts.

Using Items.Add to add Checked Items in a Checkboxlist

I am new to ASP.NET and am trying to learn it the best that I can. I am trying to add some code in the If IntRowIndex > -1 statement to mark an item SELECTED before adding it to the CheckBoxList. Where I would like the code to go is marked "***** Make ShiftCode SELECTED *****" The code is pasted below. Thanks, in advance, for any assistance.

<%@ Debug = "True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<Script Runat="Server">
Sub Page_Load( s As Object, e As EventArgs )
Dim NumberOfEmployees As Integer
Dim EmployeeSelected As Integer
Dim DayNumber As Integer = 1
Dim ShiftCode As String

Dim conEmployees As OleDbConnection
Dim cmdSelectCount As OleDbCommand
Dim cmdSelectRubyShifts As OleDbCommand

Dim dstEmployeeAvailability As DataSet
Dim dadEmployeeAvailability As OleDbDataAdapter
Dim dvwEmployeeAvailability As DataView
Dim arrValues(1) As Object
Dim IntRowIndex As Integer

Dim cmdSelectEmployees as OleDbCommand
Dim dtrEmployees as OleDbDataReader
Dim dtrRubyShifts as OleDbDataReader

conEmployees = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=C:\Documents and Settings\User\Desktop\Code\Rubys\Rubys.mdb" )
conEmployees.Open()
cmdSelectRubyShifts = New OleDbCommand("Select * From RubysDailyShifts", conEmployees)
dtrRubyShifts = cmdSelectRubyShifts.ExecuteReader()
If dtrRubyShifts.HasRows Then
dstEmployeeAvailability = New DataSet()
dadEmployeeAvailability = New OleDbDataAdapter("Select * From FrontEmployeesAvailability where EmployeeID = 1", conEmployees)
dadEmployeeAvailability.Fill(dstEmployeeAvailabili ty, "FrontEmployeesAvailability")
dvwEmployeeAvailability = dstEmployeeAvailability.Tables("FrontEmployeesAvai lability").DefaultView()
dvwEmployeeAvailability.Sort = "DayNumber, ShiftCode"

While dtrRubyShifts.Read()
If dtrRubyShifts("DayNumber") > DayNumber Then
DayNumber += 1
End If
If dtrRubyShifts("AmountOfShiftCode") > 0 Then
arrValues(0) = DayNumber
arrValues(1) = dtrRubyShifts("ShiftCode")
IntRowIndex = dvwEmployeeAvailability.Find(arrValues)
ShiftCode = dtrRubyShifts("ShiftCode")
If IntRowIndex > -1 Then
***** Make ShiftCode SELECTED *****
End If

Select Case DayNumber
Case 1
chklEmployeeAvailabilityDay1.Items.Add(ShiftCode)
Case 2
chklEmployeeAvailabilityDay2.Items.Add(ShiftCode)
Case 3
chklEmployeeAvailabilityDay3.Items.Add(ShiftCode)
Case 4
chklEmployeeAvailabilityDay4.Items.Add(ShiftCode)
Case 5
chklEmployeeAvailabilityDay5.Items.Add(ShiftCode)
Case 6
chklEmployeeAvailabilityDay6.Items.Add(ShiftCode)
Case 7
chklEmployeeAvailabilityDay7.Items.Add(ShiftCode)
Case Else
End Select
End If
End While
Else
Response.Write("There were no records in the table RubysDailyShifts")
End If
conEmployees.Close()
End Sub
</Script>

<html>
<head><title>Employee Availability</title></head>
<body>
<form runat="server">
<table>
<tr><td align=center>Wed</td><td align=center>Thurs</td><td align=center>Fri</td><td align=center>Sat</td><td align=center>Sun</td><td align=center>Mon</td><td align=center>Tues</td></tr>
<td valign="top"><asp:CheckBoxList ID="chklEmployeeAvailabilityDay1" runat="server" /></td>
<td valign="top"><asp:CheckBoxList ID="chklEmployeeAvailabilityDay2" runat="server" /></td>
<td valign="top"><asp:CheckBoxList ID="chklEmployeeAvailabilityDay3" runat="server" /></td>
<td valign="top"><asp:CheckBoxList ID="chklEmployeeAvailabilityDay4" runat="server" /></td>
<td valign="top"><asp:CheckBoxList ID="chklEmployeeAvailabilityDay5" runat="server" /></td>
<td valign="top"><asp:CheckBoxList ID="chklEmployeeAvailabilityDay6" runat="server" /></td>
<td valign="top"><asp:CheckBoxList ID="chklEmployeeAvailabilityDay7" runat="server" /></td></tr>
</table>
</form>
</body>
</html>
Mar 19 '06 #1
2 13648
I understand how to add items that aren't checked. I just would like to add the items as being checked if they pass a conditional statement.
Mar 19 '06 #2
Since noone was able to help me, I figure I would post so you all will benefit.

Dim item As ListItem
item = New ListItem(dtrRubyShifts("ShiftCode"))

If IntRowIndex > -1 Then
item.Selected = True
End If
Mar 21 '06 #3

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

Similar topics

0
by: rob | last post by:
I've been having a problem getting the text associated with checked items in a checkedlistbox control-- this article on MSDN shows how to do it: ...
4
by: Ram | last post by:
Dear Helpers, I assigened values to checkedlistbox control in the following way cList.DataSource=oDs.Tables.DefaultView; cList.DisplayMember=oDs.Tables.Columns.ToString();...
2
by: Chelimar | last post by:
Hi, I need to tell a checkbox list that if two of the items have been checked, to uncheck themselves. I need help! Thanks :) ~Chelimar
1
by: Hareth | last post by:
how do I save and open checked and unchecked items in my listview to a txt file this is kinda what I have in mind but doesnt work; I need it for listview w/ checked items and unchecked ...
2
by: jennifer1970 | last post by:
Hi. I am using VB 2005 Beta 2. I have never used a listview before. I am used to VB6. So please bear with me - I am trying to learn. I have a listview and want to be able to get the items ...
0
by: Faybert | last post by:
Hello, and Thanks in advance for any light you might shed on my troubles. I'm trying to setup a series of checkboxes, or a checkboxlist to control the results that are shown on a gridview...
3
by: Mike Collins | last post by:
If possible, how can I use a custom validator to check (client side) that if a certain value was checked in a checkboxlist? So, if they checked "great" or "good", comments are not required and if...
1
by: sherifffruitfly | last post by:
Hi, I've got a checked list box, and a "go' button on the form. Each item in the checked list box is associated with a program (say notepad, calc, etc.). When the user clicks "go", every item...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.