homepage Welcome to WebmasterWorld Guest from 54.211.95.201
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
Query for dynamic checkboxes
Show checked/unchecked using a recordset
aspdaddy




msg:942580
 10:13 pm on Aug 30, 2003 (gmt 0)

This is a query to edit a users selected widgets with checkboxes.

How do you display a list of checkboxes from a database, for 1 user, showing checked for those that the user selected and unchecked for all other available widgets.

Tables

widgets(ID,Name)
Selections(UserID,WidgetID)
Users(ID)

Something like this?
SELECT widgets.Name,widgets.ID,iif(Selections.WidgetID is NULL,""," selected ")
FROM?
WHERE Users.UserID=193

while (!rs.eof){
<%=rs(0) + "<input type=checkbox name=" + rs(1) + " " + rs(2) + "><BR>"%>
rs.movenext
}

I must have tried every combination of left, right, inner, outer join...Maybe theres a much easier way to get the same html output, Anyone know how to do this?

 

smokin




msg:942581
 11:07 pm on Aug 30, 2003 (gmt 0)

Why don't you just use the if statement on the recordset instead.

If rs(WidgetID) <> Null then
checkbox = selected
end if

aspdaddy




msg:942582
 11:18 pm on Aug 30, 2003 (gmt 0)

Smokin,

Because I couldnt figure out how to get the recordset returned with nulls.

Bit of a mission, but I have sorted it now with two recordsets and a find.

time for a break :)

strSQL="SELECT ID, Name FROM Widgets ORDER BY Name ASC"
strSQL2="SELECT WidgetID FROM Selections WHERE UserID=" & varID
set objRS=objConn.Execute(strSQL)

set objRS2=server.CreateObject("ADODB.Recordset")
objRS2.CursorLocation= 3
objRS2.Open strSQL2,objConn, 1, 3

while not objRS.eof
Response.write "<input type=checkbox name='" & objRS(0) & "'"
objRS2.Find "WidgetID=" & objRS(0),,1,1 ' search foward from 1
if not objRS2.EOF then
Response.Write " checked "
end if
Response.Write ">" & objRS(1) & "<BR>"
objRS.MoveNext
wend

smokin




msg:942583
 11:23 pm on Aug 30, 2003 (gmt 0)

good to see that you're still on the ball aspdaddy ;o)

txbakers




msg:942584
 1:44 am on Sep 1, 2003 (gmt 0)

I did it with a for loop. The data was entered csv, and I read it as csv, then parsed it into an array. Then, when it came time to check if the box should be checked, we just checked if the index matched the value.

Now this worked very well for a while, but with larger and larger recordsets it's becoming slower, so I will also try the "find" method.

aspdaddy




msg:942585
 9:17 am on Sep 1, 2003 (gmt 0)

txt,

I had to add a movefirst call, I dont know why it needs it as the find call specifies from 1.

objRS2.MoveFirst
objRS2.Find "WidgetID=" & objRS(0),,1,1

Its only an adminpage so wont get huge traffic and the options will stay at about 50, so this will do me for now. But I still think theres a way to return a single recordset with the IDs and true/false, some kinda wierd outer join......

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved