Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Thanked 0 Times in 0 Posts

    asp.net compare two datasets

    OK... here's the problem...

    I have a sign-up section on my site where people can select interests and hobbies using checkboxes, which needs to be updateable (is that a word??? LOL)

    If the user wants to update their entry then I would like to show the full list of hobbies/interests with those they have selected in the past already checked.

    I 'sort of' developed a solution that does it, but that requires looping within a loop - very inefficient and is quite a hit on the server performance.

    Anyone any ideas as to how this might be done more efficiently???

    Prefered language is VB but C# will do just as well.


    dominicall - confusing himself more and more each day

  2. #2
    New Coder
    Join Date
    Sep 2002
    Thanked 0 Times in 0 Posts

    [list=1][*]Are you using the CheckboxList control[*]Are the Checkbox control's list items static or populated via databinding?[/list=1]

    If you are using a CheckBoxList webcontrol here is one way populating the object and setting the check boxes check state.

    <%@ Import NameSpace="System" %>
    <%@ Import NameSpace="System.Data" %>
    <%@ Import NameSpace="System.Data.OleDb" %>
    <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="windows-1252" %>
    <script language="VB" runat="server">
    Sub Page_Load(sender As Object, e As EventArgs)
    	Dim oDsHobbies As New DataSet()
    	Dim oDrHobbies As DataRow
    	Dim sConn As String = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=E:\Inetpub\wwwroot\Code_Test\CheckBoxList\Hobbies.mdb"
    	' CkeckBoxList DataSet
    	Dim sSQL = "SELECT ID, Sub_Catagory FROM Hobbies WHERE Sub_Catagory Is Not Null"
    	Dim oDaHobbbies As OleDbDataAdapter = New OleDbDataAdapter(sSQL, sConn)
    	oDaHobbbies.Fill(oDsHobbies, "Hobbies")	
    	chkHobbies.DataSOurce = oDsHobbies.Tables("Hobbies").DefaultView
    	chkHobbies.DataValueField = "ID"
    	chkHobbies.DataTextField = "Sub_Catagory"
    	' Selected Intereset DataSet
    	sSQL = "SELECT Interests.HobbyID FROM Interests WHERE Interests.UserID=1;"
    	Dim oDaSelected As OleDbDataAdapter = New OleDbDataAdapter(sSQL, sConn)
    	oDaSelected.Fill(oDsHobbies, "Interests")	
    	' Create DataView for Filtering 
    	'Note: The DataView must have a Sort order set before applying  the filter
    	Dim oDvFind As DataView = New DataView(oDsHobbies.Tables("Interests"))
    	oDvFind.Sort = "HobbyID"
    	' Begin adding List Items and 
    	Dim i As Integer = 0
    	Dim nFound As Integer
    	For Each oDrHobbies In oDsHobbies.Tables("Hobbies").Rows
    		nFound = oDvFind.Find(oDrHobbies("ID"))
    		If nFound <> -1 Then
    			chkHobbies.Items(i).selected = True
    		End If
    		i =  i + 1
    End Sub
    The comtrol looks like this:

    <form id="form1" method="post" runat="server">
    	<asp:checkboxlist ID="chkHobbies" runat="server"  RepeatLayout="Table" TextAlign="Right" RepeatColumns="3" RepeatDirection="Horizontal" />
    Hoep This helps
    a credit card for a newbie from Amex: The Amex Blue card would like to start developing a credit history.

  3. #3
    Regular Coder
    Join Date
    Jan 2003
    Thanked 8 Times in 8 Posts
    I would do a SELECT of the answers they already stored and check some checkboxes based on that. Here's a very rough code example.

    Suppose you have id, name, answer1, answer2, answer3. They enter their name and they check the boxes for answer1 and answer3. So those boxes will show up as checked.

    'open your connection named MyConn
    Set RS=MyConn.execute("SELECT answer1, answer2, answer3 from MyTable where ID="&request.form("ID"))

    <input type="checkbox" name="answer1" value="yes" <%if RS("answer1")="yes" then response.write "checked"%>
    <input type="checkbox" name="answer2" value="yes" <%if RS("answer2")="yes" then response.write "checked"%>
    <input type="checkbox" name="answer3" value="yes" <%if RS("answer3")="yes" then response.write "checked"%>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts