Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET VB.NET
This is going to be a bit lengthyFrown | :( Kindly read it to the end.
 
I have a page to add products. When the user adds product, he/she is asked to add the specifications . I have all the attributes for a particular category say `Mobiles` like Camera,OS,Type etc etc. All the attributes are divided into groups(See Table Below). If the user is uploading a product in `Mobiles` category , I want to select all the groups ith the category and then the attributes in the Group and display it on the UI. Kindly go through the steps to understand the scenario.
 
Table (CategoryGroups)
 
http://i.stack.imgur.com/D20o3.png[^]
 

Step 1 : Select all the groups from a particular `NodeID`
 
Table (GroupAttributes) :
 
http://i.stack.imgur.com/qNHFW.png[^]
 
Step 2 : Display all the Attributes to the user Grouped By `GroupName` i.e `AttributeID` 1 & 2 should come under `Group 1` , `AttributeID` 3 & 4 should come under `Group 2`
 
Step 3 : For each row check if `canSelectMultiple` is `True` or `False` .
 
Step 4 : If `canSelectMultiple` is `False` Add `DropDownList` to the page and add each Value in `Value` column to the `DropDownList`[**Value column has semi colon separated values**] i.e for the 1st row Add `DropDownList` with Values "Android","Bada","Blackberry",Symbian,"iOS"
 
ElseIf `canSelectMultiple` is `True` the Add `CheckBoxes` to the page with one `CheckBox` for every value in `Value` Column.
 
Step 5 : Save the values selected by the user in DB on Button Click.
 

This is the way i intend to do it (using loops i.e FOR NEXT). Any other way to do it?? Can i do it in client end using `jQuery/Javascript`. I personally do not want to use these many loops because it would be too costly. Any help appretiated.
Posted 1-Oct-12 10:14am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Loops are really basic tools in programming. You can not avoid them. Why do you think they are "costly"? Actually you can make a code consume too many resources, but that would not be just because you use loops. Can you imagine how many loops are in jquery for example, or in the code of asp.net itself?
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 1-Oct-12 15:30pm
   
You are right, of course, my 5, but how to measure this kind of cost and manage it? Difficult question.
I provided some introductory material, good to get started -- please see my answer.
--SA
Member 7781963 at 1-Oct-12 15:36pm
   
Thanks a lot for the articles. I always thought that loops take a lot of time and therefore degrade the applications performance. Anyway, how do i place controls dynamically on the page. How do i keep a list of all the controls added to the page, because i will have to fetch the values from the controls added when the user clicks on Save Button. Kindly point me in the right direction.
Zoltán Zörgő at 1-Oct-12 15:50pm
   
I would be careful with semicolon separated lists. You will have to parse these every time you generate the page, and when you validate the answer. I would simply add a new table with the possible attributes and a foreign key to the attribute table. Actually might not be a really huge performance issue in this case, but it looks an unnecessary violation of 3NF. You don't fetch the data from the controls. They are sent by the client, you just have to get them from the POST data, and of course, validate them before you store anything in the database. So you don't need to keep a list of the controls, but you should know on what name you will get the answer. This is an other argument for using an other table: you could use the primary key of that table to generate the control names and option values. And so you have a quite simple link between the possible values and the controls.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Not the number of loops measures the cost for the performance, but many other factors, and they usually make those "multiple loops" concerns nearly insignificant.
 
This is something you need to understand first:
http://en.wikipedia.org/wiki/Computational_complexity_theory[^],
http://en.wikipedia.org/wiki/Time_complexity[^].
 
Now, the measurement and notation. Even though the notation does not have the fundamental role compared to the role of the theory itself, you won't be able to understand many statements and issues if you don't understand the notation. This is the one which is nearly always referred to:
http://en.wikipedia.org/wiki/Big_O_notation[^].
 
It's also good to understand a number of similar or related notations mentioned in the same article:
http://en.wikipedia.org/wiki/Small_o_notation#Related_asymptotic_notations[^]
 
Good luck,
—SA
  Permalink  
v2
Comments
Member 7781963 at 1-Oct-12 15:35pm
   
Thanks a lot for the articles. I always thought that loops take a lot of time and therefore degrade the applications performance. Anyway, how do i place controls dynamically on the page. How do i keep a list of all the controls added to the page, because i will have to fetch the values from the controls added when the user clicks on Save Button. Kindly point me in the right direction.
Sergey Alexandrovich Kryukov at 1-Oct-12 15:46pm
   
You are not along. This is one of the typical misjudgements of the novice. If you really have many controls, placing them "dynamically" (do you know, that there is no such thing as placing "not dynamically" or "statically"?), this is a right choice. You just should not use the Designer for that; use something like Control.Controls.Add.
 
Basically, keep references to all controls added in some array (or some collection from System.Collections.Generic) and access by iterating them in a loop. You won't need the names for the controls; all the references would be in an array/collection.
 
--SA
Member 7781963 at 1-Oct-12 16:34pm
   
I am going through this article http://www.singingeels.com/Articles/Dynamically_Created_Controls_in_ASPNET.aspx
 
Is it worth it??
Sergey Alexandrovich Kryukov at 1-Oct-12 17:28pm
   
Hard to say for sure from the first glance, but at least basic techniques are covered and the code should work. This should be enough for your to get the ideas.
The motivation is no sufficient, I would say. This is not only about extra flexibility. This is more the maintenance.
 
Imagine you really need an array of controls. Adding them with the Designer is tedious manual work, in contrast to programming where you never repeat anything, but use the loop, and the like. Good HTML is fluid, but the designer might provoke people to do some people to go fixed-position style, which is nearly always the evil...
The controls are identified in some fixed way, which you don't want to happen if you really need an array/collection of them...
 
So, there are many reasons to do it in code, so your idea was productive, a good one. Well, if you use this article as the basic reference (not it's also not too big) and also use your own brain, you won't loose anything...
--SA
Zoltán Zörgő at 1-Oct-12 15:42pm
   
Oh yes. But I think this is a little bit to much theory for the OP :) But still an extensive answer: +5!
Sergey Alexandrovich Kryukov at 1-Oct-12 15:48pm
   
Thank you, but no, I don't think this is too much. Nobody forces OP to "learn it all". It's just important to know what's involved. And to know where to go if more extensive education is eventually required. Don't you think so?
--SA
Zoltán Zörgő at 1-Oct-12 15:53pm
   
It looks, you encountered more inquisitive people, than I did. You have right, we should try to enlarge one's perspective, and maybe there are some thankful for more than just a simple solution. I hope so.
Sergey Alexandrovich Kryukov at 1-Oct-12 16:13pm
   
I think it's always better to assume more capabilities in people who we are trying to help. If this is some overkill, a person can either ask further questions (of course, some constructive attitude is expected from people getting help, otherwise it would not worth bothering about) or just get less help. But, if we assume less capabilities than the person actually have, we miss some extra chances for better help.
 
There is another important thing to it. Suppose some student cannot digest some important source of information or a hint. But this is still a hint. There is a chance that something is collected in the brain and will give a clue to this student later, as she/he gets more education. Again, this way we can use more chances for better help, even though the results would come up later.
 
And, finally, the pages in this forum may have the audience of several people. What cannot help one could be helpful for some other person. For example, I personally pay attention for what is advised to others (even though I mostly ask many questions personally, but rarely on-line). I got many good ideas, silently... Many thanks for all my colleagues who shared them...
 
--SA
Member 7781963 at 1-Oct-12 16:26pm
   
+5
Sergey Alexandrovich Kryukov at 1-Oct-12 16:31pm
   
Thank you. You see, the initial "by default" respect to a newly introduced person pays off... :-)
--SA
Espen Harlinn at 1-Oct-12 15:57pm
   
5'ed!
Sergey Alexandrovich Kryukov at 1-Oct-12 16:04pm
   
Thank you, Espen.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 1 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100