- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
.NET made it "very hard" (i.e. not drag-n-drop'able [sarcasm]) to create control arrays... and, if you use control arrays it wipes out a lot of the WYSIWYG design features - which, with a grid control that's more complex than the space shuttle, is almost required unless you're http://www.datagridgirl.com :)
Admin
Also, you didn't mention the repeated lookups into the Session object - Surely it would have been more sensible to get the user_id out first, rather than look it up 30+ times for the page load and the button click.
Admin
ben,
For i = 1 to 30
Page.FindControl("Grid" & i).user_id = session("user_id")
Next
Too lazy to typecast, but it works with Explicit off.
Admin
Or just loop through all the controls and anything starting with "Grid" will have the user_id set. FindControl might be expensive. (Like calling "session ("user_id")" 5902390390 times isn't.) :)
Admin
Scream if you want to go faster...
dim GridSet as Grid() = {Grid1,Grid2 ....
...
dim UserID=Session("User_id")
for each GridItem as Grid in GridSet
GridItem.User_id=UserID
next
Admin
I barely coded anything in ASP.NET, so forgive me that stupid question, but does the Session object work like a FIFO list? I'm just trying to get the idea behind the second code snippet.
Because if you're passing Session("user_id") to SaveUserChoices, wouldn't each follow up call on the next grid overwrite the contents each time? Especially since the guy's applying to the same set of contents (Session("user_id")) to all grids in the first snippet.
I'm not supposed to get these two snippets, am I?
Admin
I'm guessing, but I think session("user_id") is storing a class that is a grab-bag,that these grid controls either stuff their state into (on SaveUserChoices) or grope around and get their stuff (on get). And yeah it's a horrible way to do this.
Admin
In the name of our good lord, what is wrong with that code?
Its very clear to read, anyone can understand, I mean, it is obvious he wants to store the user_id in all his grids.
He is probably just following company policies on writing clear and uneficient code.
I do that all the time, the more policies one can come up with, the less efficient code you write; you get what you ask for.
Admin
He's been bumped to management since that code was written.
Admin
I work with at the place that put out that code, and the we think the guy that wrote it is one of the managers here....
Admin
Well, it may be company policy to review LOC productivity. Unwinding loops is a great way of doing it.
Admin
lol... vb
Admin
The first snippet does this lookup 30-odd times, each time assigning it to a field of a Grid object.
The second snippet does the lookup another 30-odd times, and passes it as a parameter to each Grid object's SaveUserChoices function. It could be re-written as follows: