By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

Using Items.Add to add Checked Items in a Checkboxlist

P: 3
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" )
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
Case 2
Case 3
Case 4
Case 5
Case 6
Case 7
Case Else
End Select
End If
End While
Response.Write("There were no records in the table RubysDailyShifts")
End If
End Sub

<head><title>Employee Availability</title></head>
<form runat="server">
<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>
Mar 19 '06 #1
Share this Question
Share on Google+
2 Replies

P: 3
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

P: 3
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

Post your reply

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