Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-26-2003, 08:30 PM   PM User | #1
dominicall
Regular Coder

 
Join Date: Sep 2002
Location: London
Posts: 179
Thanks: 0
Thanked 0 Times in 0 Posts
dominicall is an unknown quantity at this point
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.

Thanks

dominicall
__________________
dominicall - confusing himself more and more each day
dominicall is offline   Reply With Quote
Old 01-27-2003, 03:11 AM   PM User | #2
aCcodeMonkey
New Coder

 
Join Date: Sep 2002
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
aCcodeMonkey is an unknown quantity at this point
Question(s):
[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.


Code:
<%@ 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"
	chkHobbies.DataBind() 
	
	' 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
	Next
End Sub
</script>
The comtrol looks like this:

Code:
<form id="form1" method="post" runat="server">
	<asp:checkboxlist ID="chkHobbies" runat="server"  RepeatLayout="Table" TextAlign="Right" RepeatColumns="3" RepeatDirection="Horizontal" />
</form>
Hoep This helps
__________________
a credit card for a newbie from Amex: The Amex Blue card would like to start developing a credit history.
aCcodeMonkey is offline   Reply With Quote
Old 01-27-2003, 03:13 AM   PM User | #3
arnyinc
Regular Coder

 
Join Date: Jan 2003
Posts: 867
Thanks: 4
Thanked 8 Times in 8 Posts
arnyinc is an unknown quantity at this point
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"))
%>

<form>
<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"%>
</form>
arnyinc is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:34 PM.


Advertisement
Log in to turn off these ads.