college_amy Posted February 28, 2004 Posted February 28, 2004 Hi. I have an app that shows a registered user their information they registered with. One of the tables that is being read has some 35 fields in it. Of that 35 fields, 3 are definite to have information in them, the other 32 will either have a null value or a yes value depending on which checkbox was selected during registration. What I would like to know is if there is a way to loop through the fields with the yes value in them to display only those fields or do I need to check each field specifically in which I would use an if/then/else statement to display the information? I think the latter of the two will make the app have alot of useless programming if I do it that way. I know that I can write a SQL statement to check specific fields for Yes values, but I want all the fields with a yes value. Any help is appreciated. Thanks, Amy Quote
Moderators Robby Posted February 28, 2004 Moderators Posted February 28, 2004 Are planning on Binding the data to a control? Or just display the data in html table tags (or something) ? Quote Visit...Bassic Software
college_amy Posted February 28, 2004 Author Posted February 28, 2004 I am binding it to the page - displaying it within a table. Quote
kahlua001 Posted March 1, 2004 Posted March 1, 2004 Do you mean.. while dtrReader.read() if dtrReader("Checkbox1") = "Yes" Then Checkbox1.Checked = True end if end while I'm not too sure what your data looks like and how you want to present the layout. Quote
college_amy Posted March 1, 2004 Author Posted March 1, 2004 Kinda sorta - not really... because I would still have to write that for every field in the table of the database. See what I did was created a field for every checkbox (redundant, I know - but I needed it in a hurry and couldn't find the solution otherwise at the moment) Being that I have some 35 fields or so, I was hoping to avoid having to write or copy/paste the same code over and over.... just for loading and time sake... but I am beginning to think I will have to do it this way? Any other ideas, Kahlua001?... you seem to really know your stuff - and you have helped before too... Thanks!! Love to pick your brain... :) Quote
samsmithnz Posted March 1, 2004 Posted March 1, 2004 What you could do is extract the information for every checkbox, and then loop through the checkboxes, and make the unchecked checkboxes invisible. Quote Thanks Sam http://www.samsmith.co.nz
TechnoTone Posted March 1, 2004 Posted March 1, 2004 I'm not familiar with ASP.NET so excuse me if I get this wrong. If it was a Form then you'd have a Controls collection with all the fields. Is it the same for ASP.NET? If so, do the names of these fields match the names of the fields in the database? If they do they you should be able to loop through the fields in your Controls collection and match them against the fields in the database. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
kahlua001 Posted March 1, 2004 Posted March 1, 2004 I'm still not sure what you are working with. Do you mean you have 35 database fields and 35 checkboxes that you want to map to each other? If that is the case, why not just dynamically add the checkboxes to the page based on your database fields. Quote
college_amy Posted March 1, 2004 Author Posted March 1, 2004 actually what I am needing to do is generate a list of fields that have the "yes" value in them. I will not be putting checkboxes up for the edit part yet, what I want to do is have a central place where the user can view their information before they choose to edit it. Example output for the page would be this (at least this is what I want it to do) Review Information: Years in Service: %Userinfoyrs% Services Provided: %Alluserservices% (this is the multiple field area no. 1 about 20 db fields) service1 service2 service3 etc. Professional Affiliations: %Allproaffls% (this is the second set of multiple fields about 15 db fields) affiliation1 affiliation2 affiliation3 etc. Not all registered professionals will provide every service nor be part of every professional organization (affiliations). Hope that explains it a little bit more... I do have to say that when I actually code the update page for this section of the edit information, I have the answer on how to do this from what was already answered... Thanks :) Quote
kahlua001 Posted March 1, 2004 Posted March 1, 2004 Try something like this. <asp:Literal id="ltServicesProvided runat="server"></asp:Literal> Then.. while dtrReader.read() if dtrReader("ServicesProvided") = "Yes" then ltServicesProvided &= "<br>" & dtrReader("ServiceName") end if end while Quote
college_amy Posted March 3, 2004 Author Posted March 3, 2004 Tried that.... it gave me this error: Operator '&' is not defined for types 'System.Web.UI.WebControls.Literal' and 'String'. So then I thought I would be slick and remove the & operator... and it then gave me this: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Literal'. Changed the literal to a label and got the exact same thing... Any suggestions as to why? Thanks, Amy Quote
Administrators PlausiblyDamp Posted March 3, 2004 Administrators Posted March 3, 2004 You probably need to use the literal's (or label's) .Text property rather than the control itself. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
college_amy Posted March 3, 2004 Author Posted March 3, 2004 Duh... why didn't I think of that... geesh... Thanks.. :) I knew that.. really I did.... ;) geesh - sometimes the simplest things.......lol Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.