Forums

ASP

This topic is locked

Database - Use checkboxes to select fields in resu

Posted 08 Sep 2002 22:04:13
1
has voted
08 Sep 2002 22:04:13 alison mcl posted:
Hi
I've searched all round the web for an answer to this before posting and have found quite a few people asking the question but never any answer to it. I'm using asp but any assistance for any language could help start me in the right direction.

I've got a webpage where I would like the user to select checkboxes that they would then submit and on the results page be able to view only those fields/columns they have opted to view. (i.e. the checkboxes relate to the columns they would see).

I know this is the opposite way round and normally you search for criteria in records but I just can't think of a way round this to get it to work. The fields themselves have just numbers in them so there are no distinct features between the fields.

Am I approaching it from the wrong angle (I just have one table with the fields and records) and is it possible?

Any help VERY much appreciated as my brain feels like its junked and my nails are a bit worse for wear!

cheers
B

Replies

Replied 09 Sep 2002 13:03:51
09 Sep 2002 13:03:51 Andrew Watson replied:
You should be able to achieve this with conditional regions....

your form should loop through all items in the recordset returning a checkbox called the fieldname.

now when submitted you should have form data that says which was checked.

Then just create a layout for ALL columns and then for each column put it in a conditional region ie only show this column if it exists in the form data.

if i can get a little time today ill pop up some sample code....

cheers

LEED


:: Son, im Thirty.... ::
Replied 09 Sep 2002 13:36:08
09 Sep 2002 13:36:08 Andrew Watson replied:
This is one way of doing it, not the best but it should get you started. not the most dynamic way but it will work.

<font color=red>FORM PAGE</font id=red>

<pre id=code><font face=courier size=2 id=code>

&lt;!--#include file="Connections/Test.asp" --&gt;
&lt;%
set rsColumns = Server.CreateObject("ADODB.Recordset"
rsColumns.ActiveConnection = MM_Test_STRING
rsColumns.Source = "SELECT * FROM MyTable"
rsColumns.CursorType = 0
rsColumns.CursorLocation = 2
rsColumns.LockType = 3
rsColumns.Open()
rsColumns_numRows = 0
%&gt;


&lt;html&gt;
&lt;head&gt;

&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;

&lt;body bgcolor="#FFFFFF" text="#000000"&gt;
&lt;form name="form1" method="post" action="ViewColumns.asp"&gt;
&lt;Table&gt;
&lt;% for each f in rsColumns.Fields %&gt;
&lt;tr&gt;&lt;td&gt;
&lt;input type="checkbox" name="&lt;%= (f.Name) %&gt;" value="show"&gt;
&lt;/td&gt;&lt;td&gt;
&lt;%= (f.Name) %&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;% next %&gt;
&lt;/Table&gt;
&lt;br&gt;
&lt;input type="submit" name="Submit" value="Submit"&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
&lt;%
rsColumns.Close
%&gt;
</font id=code></pre id=code>

<font color=red>TABLE PAGE</font id=red>

<pre id=code><font face=courier size=2 id=code>

&lt;%@LANGUAGE="VBSCRIPT"%&gt;
&lt;!--#include file="Connections/Test.asp" --&gt;
&lt;%
set rsColumns = Server.CreateObject("ADODB.Recordset"
rsColumns.ActiveConnection = MM_Test_STRING
rsColumns.Source = "SELECT * FROM MyTable"
rsColumns.CursorType = 0
rsColumns.CursorLocation = 2
rsColumns.LockType = 3
rsColumns.Open()
rsColumns_numRows = 0
%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;
&lt;body bgcolor="#FFFFFF" text="#000000"&gt;
&lt;table width="100%" border="0" cellspacing="0" cellpadding="2"&gt;
&lt;tr&gt;
&lt;% If Request.Form("Column1" = "show" Then %&gt;
&lt;td&gt;Col 1&lt;/td&gt;
&lt;% End If %&gt;
&lt;% If Request.Form("Column2" = "show" Then %&gt;
&lt;td&gt;Col 2&lt;/td&gt;
&lt;% End If %&gt;
&lt;% If Request.Form("Column3" = "show" Then %&gt;
&lt;td&gt;Col 3&lt;/td&gt;
&lt;% End If %&gt;
&lt;% If Request.Form("Column4" = "show" Then %&gt;
&lt;td&gt;Col 4&lt;/td&gt;
&lt;% End If %&gt;
&lt;% If Request.Form("Column5" = "show" Then %&gt;
&lt;td&gt;Col 5&lt;/td&gt;
&lt;% End If %&gt;
&lt;% If Request.Form("Column6" = "show" Then %&gt;
&lt;td&gt;Col 6&lt;/td&gt;
&lt;% End If %&gt;
&lt;/tr&gt;
&lt;% While Not rsColumns.EOF %&gt;
&lt;tr&gt;
&lt;% If Request.Form("Column1" = "show" Then %&gt;
&lt;td&gt;&lt;%=(rsColumns.Fields.Item("Column1".Value)%&gt;&lt;/td&gt;
&lt;% End If %&gt;
&lt;% If Request.Form("Column2" = "show" Then %&gt;
&lt;td&gt;&lt;%=(rsColumns.Fields.Item("Column2".Value)%&gt;&lt;/td&gt;
&lt;% End If %&gt;
&lt;% If Request.Form("Column3" = "show" Then %&gt;
&lt;td&gt;&lt;%=(rsColumns.Fields.Item("Column3".Value)%&gt;&lt;/td&gt;
&lt;% End If %&gt;
&lt;% If Request.Form("Column4" = "show" Then %&gt;
&lt;td&gt;&lt;%=(rsColumns.Fields.Item("Column4".Value)%&gt;&lt;/td&gt;
&lt;% End If %&gt;
&lt;% If Request.Form("Column5" = "show" Then %&gt;
&lt;td&gt;&lt;%=(rsColumns.Fields.Item("Column5".Value)%&gt;&lt;/td&gt;
&lt;% End If %&gt;
&lt;% If Request.Form("Column6" = "show" Then %&gt;
&lt;td&gt;&lt;%=(rsColumns.Fields.Item("Column6".Value)%&gt;&lt;/td&gt;
&lt;% End If %&gt;
&lt;/tr&gt;
&lt;% rsColumns.Movenext
Wend
%&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;%
rsColumns.Close()
%&gt;

</font id=code></pre id=code>

:: Son, im Thirty.... ::

Reply to this topic