Last post Apr 07, 2009 07:56 AM by Ivan VB
Apr 06, 2009 04:31 PM|Ivan VB|LINK
PROBLEM OVERVEIW: everything "runs", it never crashes, it populates the checkboxlist on the page, it even calls BindCheckBoxList during the databind but it never checks the boxes.
I have debugged and stepped through the stop points comments are below. any help = greatly appreciated. Thanks in advance.
FRONT END CODE:
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True" DataSourceID="AccessDataSource2"
DataTextField="Abbreviation" DataValueField="Abbreviation" OnDataBinding="BindCheckBoxList" OnSelectedIndexChanged="BindCheckBoxList">
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/app_data/WaterQuantity.mdb"
SelectCommand="SELECT * FROM [tblMemberAssociations] ORDER BY [AssociationName]">
BACK END CODE:
Protected Sub BindCheckBoxList(ByVal sender As System.Object, ByVal e As System.EventArgs)
'check box if Abrreviation value from tblMemberAssociations is in
'Abrreviation tblMembershipAccounts_MemberAssociations for this user_name
Dim container As CheckBoxList
container = DirectCast(sender, CheckBoxList)
Dim userName As String = Page.User.Identity.Name
Dim cn As OleDbConnection = New OleDbConnection(ConfigurationManager.AppSettings("ConnectionString"))
Dim myCommand As New OleDbCommand
myCommand.Connection = cn
Dim dbCommand As New OleDbCommand
dbCommand.Connection = cn
dbCommand.CommandText = "SELECT * FROM tblMembershipAccounts_MemberAssociations " & _
"WHERE USER_NAME='" & userName & "'"
Dim objdatareader As OleDbDataReader
objdatareader = dbCommand.ExecuteReader()
'READ DATA HERE
Do While objdatareader.Read() = True
Dim checkValue As String = objdatareader("Abbreviation").ToString()
'****SUSPECT PROBLEM IS HERE. currentCheckBox is ALWAYS null; Reference appears wrong?
Dim currentCheckBox As ListItem = container.Items.FindByValue(checkValue)
If Not IsNothing(currentCheckBox) Then
'****NEVER makes it inside the if statement
currentCheckBox.Selected = True
Catch myerror As OleDbException
Dim strErr As String = "There was an error reading from the database: " & myerror.Message
ASP.net AJAX VB.net
Apr 06, 2009 05:00 PM|Team929|LINK
Try Checboxlist DataBound?
Apr 06, 2009 05:05 PM|Ivan VB|LINK
Could you be a little more specific please?
Apr 06, 2009 05:59 PM|Team929|LINK
<Edited.. didn't realize my post made no sense after re-reading just now..>
Anyway, how about changing the event for the CheckList from OnDataBinding to OnDataBound? Perhaps this is a timing issue if you say that nothing crashes but it's not producing the results you want.
Apr 07, 2009 07:56 AM|Ivan VB|LINK
That did it!!! Thank you so much. I would never have thought to do that. I am marking your post as the answer. Have a great day and thanks again.