A while ago, I had resigned myself to the fact that I would have to custom-build my own shopping cart for a site I'm working on. Well, I'm sure I could have bought something to do relatively the same thing, but what fun is that for a coder like me?
Anyway, I got to the part where I actually display the items in the cart. I was happily coding along in my usual ASP mindset, adding forms, hidden input tags, and... whoops. That's not going to work, this is ASP.Net. Doh.
So I switched out to a DataGrid. The first thing I figured out is that I have absolutely no idea how to use a DataGrid. The second thing I figured out, and this one took a while, is that the CssClass property of the styles are applied to the table row, and not each table cell. Very annoying, as I ended up creating my own custom class to fix that. Easy enough:
Public Class DataGrid
Inherits WebControls.DataGrid
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
MyBase.OnPreRender(e)
For Each dgiItem As DataGridItem In Me.Items
For Each tc As TableCell In dgiItem.Cells
If dgiItem.ItemType = ListItemType.Item Then
tc.CssClass = Me.ItemStyle.CssClass
ElseIf dgiItem.ItemType = ListItemType.AlternatingItem Then
tc.CssClass = Me.AlternatingItemStyle.CssClass
End If
Next
Next
End Sub
End Class
Next came figuring out how to add a title to the grid. If you notice on all of the sites I host, there's a title bar for each table in the content section. Well, there wasn't an easy way to do this. I couldn't figure out how to access the table control that the DataGrid populates, so I ended up just stacking a one-row table on top of it.
Now I had to figure how to put the total of the order in the footer, but there are enough good articles on how to do that, so that didn't take long. Adding a remove button to remove a product someone doesn't want from the cart was fairly easy as well.
The fun came in having to allow them to change the quantity on the fly. That turned out to be more of a project than I was expecting. There were two approaches I was considering, and of course I took the difficult one: using the onblur method of an input tag to populate two hidden fields with the ItemID I want to update the quantity of and the new quantity, as well as activate a hidden button on the form.
Phew! I wasn't expecting so much work out of what would be maybe an hour of work in classic ASP.
This is my blog where I give my thoughts and opinions on various topics and share my creative endeavors with the world. I run two personal blogs, but combine them here for ease of access.
Blogger - My oldest blog using the Blogger platform contains posts full of opinions, gaming, and code.
Tumblr - Tumblr posts are all about my creative side, containing music, videos, writings, and updates on my web creations.
You can select a category below to view the latest post, or browse thorugh the posts using the navigation found at the top and bottom of each post.
In California, truck license plates are 7 characters, all numbers except for one letter in either the second or the sixth position. Whenever that letter is an X, I get nerd snipped into treating it as a multiplication problem and solving it in my head.
we should have paid more attention to the cats who, for decades, put their bodies on the line to walk on keyboards and sit on laptops and prevent us from programming
Former 2 time world champion DogPlayingTetris becomes the first player to ever rollover the level counter in NES Tetris, performing what's known in the community as "Rebirth". Final score: 29,486,164, 4216 lines, level 347 (256 + 91)... all huge world records. #tetris
I'd also love a 6 hour layover overnight instead of taking the red eye I was going to take and be 7 hours later getting into Cleveland than I wanted, why do you ask? #airporthell
Why yes, I'd love to leave at 4:40 to get to the airport at 6:20 for an 8:20 flight that got delayed to 9:05 which is too late for my connection so now I'm on a 10:20 flight instead. Why do you ask? #airporthell
@shanselman Who at Microsoft do I have to bribe to fix ADO so that those of us on dark mode who copy/paste text from one task to another can do so without our friends on light mode seeing dark text on a dark background?
I updated the blog post with a statement from Revival. While I'm not particularly happy with Revival's decision, I understand their motives. It's just a shame that it was someone from Interplay that had to go and do this. "By games for gamers" my ass.
Damn, got another Tetris world record! This time in the arcade variant developed by Atari. 6,008,005 points, 5,386 lines, round 363. Be warned, it's nearly FIVE HOURS. https://www.twitch.tv/videos/2131759212