473,547 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Items.Add to add Checked Items in a Checkboxlist

3 New Member
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="Syst em.Data" %>
<%@ Import Namespace="Syst em.Data.OleDb" %>

<Script Runat="Server">
Sub Page_Load( s As Object, e As EventArgs )
Dim NumberOfEmploye es As Integer
Dim EmployeeSelecte d As Integer
Dim DayNumber As Integer = 1
Dim ShiftCode As String

Dim conEmployees As OleDbConnection
Dim cmdSelectCount As OleDbCommand
Dim cmdSelectRubySh ifts As OleDbCommand

Dim dstEmployeeAvai lability As DataSet
Dim dadEmployeeAvai lability As OleDbDataAdapte r
Dim dvwEmployeeAvai lability As DataView
Dim arrValues(1) As Object
Dim IntRowIndex As Integer

Dim cmdSelectEmploy ees as OleDbCommand
Dim dtrEmployees as OleDbDataReader
Dim dtrRubyShifts as OleDbDataReader

conEmployees = New OleDbConnection ( "PROVIDER=Micro soft.Jet.OLEDB. 4.0;DATA Source=C:\Docum ents and Settings\User\D esktop\Code\Rub ys\Rubys.mdb" )
conEmployees.Op en()
cmdSelectRubySh ifts = New OleDbCommand("S elect * From RubysDailyShift s", conEmployees)
dtrRubyShifts = cmdSelectRubySh ifts.ExecuteRea der()
If dtrRubyShifts.H asRows Then
dstEmployeeAvai lability = New DataSet()
dadEmployeeAvai lability = New OleDbDataAdapte r("Select * From FrontEmployeesA vailability where EmployeeID = 1", conEmployees)
dadEmployeeAvai lability.Fill(d stEmployeeAvail ability, "FrontEmployees Availability")
dvwEmployeeAvai lability = dstEmployeeAvai lability.Tables ("FrontEmployee sAvailability") .DefaultView()
dvwEmployeeAvai lability.Sort = "DayNumber, ShiftCode"

While dtrRubyShifts.R ead()
If dtrRubyShifts(" DayNumber") > DayNumber Then
DayNumber += 1
End If
If dtrRubyShifts(" AmountOfShiftCo de") > 0 Then
arrValues(0) = DayNumber
arrValues(1) = dtrRubyShifts(" ShiftCode")
IntRowIndex = dvwEmployeeAvai lability.Find(a rrValues)
ShiftCode = dtrRubyShifts(" ShiftCode")
If IntRowIndex > -1 Then
***** Make ShiftCode SELECTED *****
End If

Select Case DayNumber
Case 1
chklEmployeeAva ilabilityDay1.I tems.Add(ShiftC ode)
Case 2
chklEmployeeAva ilabilityDay2.I tems.Add(ShiftC ode)
Case 3
chklEmployeeAva ilabilityDay3.I tems.Add(ShiftC ode)
Case 4
chklEmployeeAva ilabilityDay4.I tems.Add(ShiftC ode)
Case 5
chklEmployeeAva ilabilityDay5.I tems.Add(ShiftC ode)
Case 6
chklEmployeeAva ilabilityDay6.I tems.Add(ShiftC ode)
Case 7
chklEmployeeAva ilabilityDay7.I tems.Add(ShiftC ode)
Case Else
End Select
End If
End While
Else
Response.Write( "There were no records in the table RubysDailyShift s")
End If
conEmployees.Cl ose()
End Sub
</Script>

<html>
<head><title>Em ployee Availability</title></head>
<body>
<form runat="server">
<table>
<tr><td align=center>We d</td><td align=center>Th urs</td><td align=center>Fr i</td><td align=center>Sa t</td><td align=center>Su n</td><td align=center>Mo n</td><td align=center>Tu es</td></tr>
<td valign="top"><a sp:CheckBoxList ID="chklEmploye eAvailabilityDa y1" runat="server" /></td>
<td valign="top"><a sp:CheckBoxList ID="chklEmploye eAvailabilityDa y2" runat="server" /></td>
<td valign="top"><a sp:CheckBoxList ID="chklEmploye eAvailabilityDa y3" runat="server" /></td>
<td valign="top"><a sp:CheckBoxList ID="chklEmploye eAvailabilityDa y4" runat="server" /></td>
<td valign="top"><a sp:CheckBoxList ID="chklEmploye eAvailabilityDa y5" runat="server" /></td>
<td valign="top"><a sp:CheckBoxList ID="chklEmploye eAvailabilityDa y6" runat="server" /></td>
<td valign="top"><a sp:CheckBoxList ID="chklEmploye eAvailabilityDa y7" runat="server" /></td></tr>
</table>
</form>
</body>
</html>
Mar 19 '06 #1
2 13655
EnjoyLife
3 New Member
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
EnjoyLife
3 New Member
Since noone was able to help me, I figure I would post so you all will benefit.

Dim item As ListItem
item = New ListItem(dtrRub yShifts("ShiftC ode"))

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
2851
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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskdeterminingcheckeditems.asp EXCEPT- it doesnt seem to work when you databind the control to a dataset. When you...
4
29091
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(); cList.ValueMember=oDs.Tables.Columns.ToString(); where oDs is DataSet
2
1466
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
2320
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 private void btnSave_Click(object sender, System.EventArgs e)
2
9919
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 from each row when the row is checked. I am using columns too for formatting puroses. I found examples of how to add columns and followed them -...
0
1983
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 control. I have a column in my database that hold the current status of the items in there. If I used a checkboxlist and populate it with my options,...
3
1169
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 they checked "not so great" or "awful", comments would be required before allowing the page to post.
1
2004
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 that is checked is to be run. I'm looking for an elegant and extensible way to do this. I'm currently using an if block, which just seems silly to...
0
7507
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7698
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7461
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7794
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6030
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5361
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.