Gridview,CheckboxList and ObjectDataSource

A

avital

Hi,

Hope someone can please help.

I have a Gridview with a checkboxlist. On edititemTemplate I want the
checkboxlist items to be selected as returned from the database.

In the database I have a table called PrescriptionDetails with a field
called Weekdays that can store data in the following format:
Monday,Tuesday,Thursday,

I have a function called GetAllPrescriptionDetails that returns the
data in the database.

When the Gridview is in Edit mode I want the checkboxlist to select the
items so if there are the values Monday and Tuesday then the Monday
item will be selected and the Tuesday item. Also the values are stored
with a , in the database so I need to split the values. I am using an
objectDataSource.

How can I loop through the items and select them?


<asp:checkboxlist id="ChkWeekDays" runat="Server"
datatextfield="WeekDays"

datavaluefield="WeekDays" ondatabound="Preselect_Checkbox"
repeatcolumns="2"

repeatdirection="Vertical" style="float: left">



</asp:checkboxlist>
_______________-

<

asp:eek:bjectdatasource deletemethod="DeletePrescriptionDetails"
insertmethod="InsertPrescriptionDetails"

id="objDetails" runat="server" selectmethod="GetAllPrescriptionDetails"
updatemethod="UpdatePrescriptionDetails"

typename="GridViewClasses">

<selectparameters>

<asp:controlparameter controlid="hdnPresID" name="PrescriptionID"
propertyname="Value"

type="Int32" />

</selectparameters>

</asp:eek:bjectdatasource>
______________________________________________

Public Function GetAllPrescriptionDetails(ByVal PrescriptionId As
Integer) As List(Of GridViewClasses)

Dim userList As New List(Of GridViewClasses)()

Dim myCommand As New SqlCommand("GetPrescriptionDetails", myConnection)

myCommand.CommandType = CommandType.StoredProcedure

myCommand.Parameters.AddWithValue("@PrescriptionID", PrescriptionId)

myConnection.Open()

Dim reader As SqlDataReader = myCommand.ExecuteReader()

While reader.Read()

Dim user As New
GridViewClasses(DirectCast(reader("PrescriptionDetailId"), Integer),
DirectCast(reader("PrescriptionId"), Integer),
DirectCast(reader("MedicineId"), Integer),
DirectCast(reader("MedicineGenericName"), String),
DirectCast(reader("RouteId"), Integer), DirectCast(reader("RouteName"),
String), DirectCast(reader("InfusionVolumeTitle"), String),
DirectCast(reader("InfusionRate"), Integer),
DirectCast(reader("ActualDose"), Integer),
DirectCast(reader("InfusionVolumeID"), Integer),
DirectCast(reader("Weekdays"), String),
DirectCast(reader("PrescriptionDate"), DateTime))

userList.Add(user)

End While

myConnection.Close()

reader.Close()

myCommand.Dispose()


If userList IsNot Nothing AndAlso userList.Count > 0 Then

Return userList

Else

Return Nothing

End If

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top