Don’t Drink The Water

June 17th, 2010

For those of you who don’t know me, here’s a little background information before I tell this story:

I have a pair of Border Collies. Reilly, my first, just turned one in May and the second, Mackenna will be one at the end of this month. I work from home which allows me the flexibility and time to train and take care of two very active puppies. They are my constant companions and do everything with me to the point where most of the time I appear to be some strange being with ten legs, two tails and three heads. If you know nothing about border collies, you can read more here, but to summarize, they are like the rocket surgeons of the dog world with the stamina and athleticism of Olympic athletes… so they are a lot of work to own, but well worth it if you are able and willing to put in the time and effort they require. Reilly is the more intense of the two and demands the most exercise. She wants to play (in her mind she’s working) all the time. She basically has two speeds, sleep and full speed ahead.

Just got groomed

Reilly (left) & Mackenna (right)

This past weekend My girlfriend Heather, a couple of friends and myself went boating. Of course the dogs came along. We got to the beach where we planned to spend the day, anchored the boat, strapped the dogs into their life jackets and I got in the water with them and took them to the beach to play. It was a hot day, so my main concern with them playing out in the sun was heat stroke or something similar, so I made sure the game of fetch kept them in the water as much as possible. Shortly after starting our game, a woman and her children came over to meet the dogs. The kids wanted to play with Reilly, so I showed them some hand signals they could use to get her to do tricks and the kids kept Reilly occupied while Mackenna stuck by me and dug holes on the beach.  After about an hour, I decided to take the dogs back to the boat to rest for a bit. Reilly looked exhausted and didn’t even want to make the swim back to the boat, so I used the handle on the back of her life jacket to pull her through the water and lifted her onto the swim platform. From there, she had a hard time climbing into the boat, but as much as she had been running and swimming, I just thought she needed to sleep for a while.

Once on the boat, she started acting strange. She sat up with her eyes closed as if she was forcing herself to stay awake, and that’s when I started getting a bit concerned. I offered her some water but she wouldn’t drink and then she got sick. A minute later she was sick again. She was lying on her side and moaning and when I checked her gums, they were gray. This is when it was decided that she had to be rushed to an emergency vet.

We pulled anchor and hauled ass back to the marina. As soon as we were tied up to the end of the dock, I grabbed her, jumped off the boat and ran up the dock to get her to my car. I was upset, and running and still had no idea where I was going to take her. Heather found the closest vet that had emergency hours and sent the address to my phone. I don’t know how I did it, but I remember at one point I was holding my phone in one hand, entering an address in my GPS with the other and still driving.  I had a few moments where I was certain Reilly was going to die lying next to me in the car. That forty minute drive felt like an eternity.

When we arrived at the vet, they were expecting us and immediately took Reilly to the back to start looking her over. There was paperwork for me to fill out, which included deciding what they should do if her heart were to stop. I’ve had three panic attacks in my life, that was when the third started. I was already upset and making a life or death decision on the spot while trying to consider a dog’s quality of life while not being selfish about it while simultaneously facing the fact that her heart stopping was a distinct possibility was more than I could handle at that point. I managed to make a choice and was escorted into an exam room along with a box of tissues and a cup of water. Once I regained my composure and calmed myself down a bit, I sat waiting for what felt like forever.

Eventually a vet came in to explain what was happening. They were running some blood tests and checking for a couple things. Her temperature was normal, but after 40 minutes in the car with all A/C vents pointed at her, they weren’t ready to rule out heat stroke yet. They did think that the most likely diagnosis was water intoxication (she called it water toxicity, but I’ve since learned that they are the same thing). The basically means that Reilly drank too much water. She said that Reilly would need to stay in the hospital and it would possibly be as long as three more days. After approving the treatment, I was allowed to go sit with her for a bit while she was receiving the first of several IVs. She was a bit out of it, but made several attempts to get up and leave the crate, which to me was a sign that she was already returning to normal. Heather arrived shortly after that with Mackenna and she was able to have a short visit with Reilly while I kept and eye on Mackenna.

I received a call from the vet around 11:00PM with an update and she told me that Reilly was doing much better. I was told that they would call if there were any problems overnight, but if I didn’t hear anything, I could take that as good news. She also said that if Reilly continued to improve at the same rate, I might be able to take her home as early as Sunday evening.

I spent Saturday night waking up hourly to see if I had missed a phone call… I hadn’t and when I got a call in the morning, it was good news. Reilly’s latest set of tests had all come back normal, she had eaten breakfast without getting sick and they told me I could get her anytime after noon. I arrived promptly at 12:06 to pick her up. She spent most of Sunday sleeping, slept a little more than normal Monday morning and was back to her normal, crazy self that afternoon.

A quick reaction, good quality medical care and the fact that Reilly is young and healthy made the ending a happy one in our case, but water intoxication is a serious issue and even a slight delay could have had disastrous results. If you have an active dog that spends time in or around water, you need to be aware of what happens. Basically, when too much water is ingested than the kidneys can process, the water dilutes the electrolyte balance in the body and the cells begin to swell from absorbing the excess water. When this hits the brain, the brain swells and can cause all kinds of problems such as brain damage and cardiac arrest. The personnel at the VCA Newark Animal Hospital were great and knew what to look for right away based on the information I gave them, but from doing research, I have learned that a lot of vets are not used to seeing this and may not consider it for a diagnosis, so if you have a dog that loves the water, you should read about it and be prepared to bring it up if you find yourself in a similar situation.

In the end, I had a very stressful weekend and I don’t have nearly as much money in the bank, but Reilly is healthy and will continue to provide me with years of entertainment and companionship and that is what’s really important.

Reilly loves to swim, so we aren’t going to stop doing it, but swimming will be for much shorter periods of time with longer play sessions on dry land in between.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Andrew Dogs , ,

Dear Census

March 23rd, 2010

You’re broke! And by broke, I mean in the financial sense. You wanna know why? It’s because your system is outdated and broken (in the “doesn’t work anymore” way). Ever hear of a little thing called the world wide web? I know it may seem like a fad right now, but I have a feeling this thing might just catch on.

You sent me a paper letter earlier this year letting me know the census was coming, which was great because the television and radion ad campaign just didn’t drive the point home… until I recieved that letter, I had no idea this was going to happen. Then you sent me a paper form to fill out and mail back. Three days later, I got your postcard, thanks, but there isn’t even a pretty picture so it was kind of a let down. So you have sent out mail three times, and there will be a fourth mailing when I send my form back.

I have a few problems with the way you have been doing things, let me share them with you now.

  1. In case you haven’t noticed, there’s a pretty big push to cut down on paper, it requires trees to be cut down, power from fossil fuels to be created, shipped, printed on, cut and then shipped again when you send it to me.
  2. The postal service isn’t exactly cleaning up in the income department, so I can’t imagine they are mailing your stuff to every single household in the United States for free. You’ve blown through your budget, which BTW, was partially my money to start with.
  3. It’s the census, did you really need to hire actors and an overpriced (they are all overpriced) marketing firm to come up with creative commercials to tell us about it? There’s that budget thing again.
  4. When I fill out this form and mail it back, how many people will it take to process and compile the information? Will you be recycling all of those forms?
  5. What’s up with the timing… don’t you know it’s tax season? (More on this later)
  6. Between the IRS, Public Schools, Motor Vehicle Commission and various other federal and state entities, shouldn’t you already know a lot of this stuff? If I didn’t pay my taxes, you bet your ass the IRS would gather enough information to find me… maybe you should ask them where they get their information.

I’m not one to complain without offering solutions, so here are some ideas in no particular order:

  • Put the form on the web! Run a simple commercial and send me to the address in January to register. Once registered, send me email when it’s time to fill out the form and don’t send me any mail. If a household isn’t registered online, then you can send the mail.
  • On a related note, give me an incentive to register online, it doesn’t have to be big, but it’ll get more people to do it… and make the incentive something that doesn’t need to be mailed (that would defeat the purpose of the online form), like a credit for one song on iTunes. You could probably strike a good deal with Apple and it would cost you less than one of your 4 pieces of mail per household.
  • Don’t spend so much on commercials. Hire some marketing students as interns, have them put together a simple, short and to the point commercial. One commercial! Run it every once in a while, but don’t over do it. It isn’t that hard… I wrote a commercial in highschool and won a contest… I wrote it when I walked into class and realized I hadn’t done the assignment and it was due… like I said, it isn’t that hard and it certainly isn’t worth 200+ dollars per hour.
  • Hey it’s tax season, if you don’t want to put the form on the web, couldn’t you get in with the IRS and make it part of the tax forms (and they have stuff online, so it would be like a double whammy)? You all work for the same government, right? You tell me it’s against the law to not fill out the census, so is not paying your taxes… make it easy for me to do the right thing. And honestly, the people that don’t do their taxes, probably care a lot less about this. BTW, I was wondering, since you couldn’t put my name on the mailing to begin with, if I don’t fill it out, how will you know I didn’t? And what legal action can you take against somebody you don’t know about?
  • Get access to the information the government already has about me. Compile it and pre-fill my online census form with what you know. Let me correct anything that is wrong or has changed and I’ll add anything that you didn’t already know. Then give the updated information back, so I don’t have to fill out so many forms at the DMV.
  • Did I mention putting the form online?

Now that we’ve covered how you can fix your general stupidity, let’s look at some of the specific questions you are asking. I’ll go in order so you don’t get confused.

  1. Question #1 asks how many people are living or staying in my home. It specifically says to include anybody living/sleeping there and leave anybody who is deployed for the military, in college, etc. off of the form (which means the whole form in my interpretation). Then question #2 asks about additional people living in my home that I didn’t include in question 1… I don’t see anything in the instructions that would leave people out of question 1 and still qualify them for question 2. Maybe I’m missing something… or maybe this is some kind of test.
  2. Question #4 wants my phone number so you can call if you don’t understand an answer… my guess is if I filled out question #2 with an answer other than “No additional people” I would get a phone call. You could probably remove questions 2 and 4 and save us all some time.
  3. Questions #7… are you serious? Why do you need my age and date of birth? If you have the date I was born, some simple math would get you my age… I bet most 1st graders would figure that one out, maybe you should hire them to compile your data. That might not be allowed due to child labor laws, so instead, you could get a big shippment of bananas and some chimps, and I would have to put my age right next to my date of birth.
  4. Questions 8 asks if I’m hispanic with some specific options, then 9 asks for my race. Shouldn’t the options from 8 just be available for 9? 9 specifically asks me to fill out one or more boxes… what if I’m hispanic? You know that from #8 and that isn’t an option on #9. Do I need to take my answer from 8 and put it in the “other” box on 9? Turns out you don’t consider hispanic origins to have anything to do with race for the census… now I’m really confused. How is Chinese a race, but Cuban is not?

That covers most of the questions, which begs the question: what about the other important demographic information? Level of education, income range, profession, pets, do my kids (hypothetical, I don’t have any) go to public or private school, etc. Your commercials are all about how the census will help level resources for schools and hospitals but I would think a little more information in those areas might help a little more than number of people and race. If you are going to waste this much tax money, at least get some more useful information out of it!

This could all be done more efficiently, with a smaller budget and yeild some more useful results if you gave it some thought. Get with the times, get rid of the red tape and commitees and focus on doing something the smart way for a change!

Disclaimer: This is a rant. I know very little about how the census bureau actually handles things so it might not be as bad I make it sound, but pile of mail on my desk and the fact that they blew through their budget leads me to believe that researching the topic would make me more angry and this post would become much less family friendly.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Andrew Broken Things, Thoughts

I’m Back

March 22nd, 2010

It has been a long time since I actually wrote anything here. Things come up, life changes and sometimes priorities shift quite a bit. Part of the reason I stopped was that I tried too hard to maintain a technical focus and when I wanted to write about other topics, I attempted to start independent blogs, which required me to write enough content to justify the creation of another site. This started getting out of hand, and it became overwhelming.

I was recently inspired by a friend who started blogging, he writes whatever he wants and manages to be quite entertaining while doing it. I figured, hey this is my blog, I can do whatever I want with it! So no more focus, no more independent sites by topic, no more wanting to write but not feeling like I have the right place to do it. I’m putting it all here. Read what you like, ignore the rest or ignore the whole thing, I am now writing simply because I want to.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Andrew Uncategorized

Combobox != DropDownList

January 10th, 2009

I am currently working on a fairly involved interface to administer data for a system that I built at work. In order to streamline the process, I am working on elements that allow users to select existing items for supporting data or create a new option inline. For some of the more involved elements, I am working out inline forms; for simpler items that can be captured as a single field of input, I wanted to use a combobox element. This is a web application and I am a big fan of jQuery, so I decided to look for a plugin that would give me the combobox functionality I was after.

What I found was a bit surprising. I found several pages of Google results that showed a fundamental lack of understanding around the term combobox.

Most of the information and plugins I found were basically replacements or enhancements for the HTML Select element. The select element gives you a dropdownlist of pre-set options to choose from. The plugins that I found were nice and offered some benefits over the standard select element, but they were not comboboxes.

The “combo” part of the name is short for combination. A combobox is the combination of a textbox and a dropdown. It should allow preset options while still allowing for a new value to be entered as plain text.

My guess is that if you are reading this, you knew this already, but maybe not. Maybe if, like me, you thought this was common knowledge, it will save you some of the surprise when you encounter it.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Andrew Back to Basics , ,

Change Object Owner in SQL Server

September 21st, 2008

When creating a new object in SQL Server while logged in using windows authentication, the object belongs to your username by default. I seem to forget this all the time and end up needing to change the owner of the new object to dbo. This is simple to do, yet I always end up having to search for the exact name of the stored procedure that does this. This post is for my future reference, hopefully it’ll help somebody else too (maybe even you).

To change an object’s owner all you need to do is run:

sp_changeobjectowner 'tablename', 'dbo'

Replace “tablename” with the name of the object you need to change and “dbo” can be changed to another owner if needed… I find that I am usually making the change to dbo.

Hope this helps somebody else.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Andrew SQL Server , ,

New Pics on Flickr

September 19th, 2008
Riverfest Fireworks

Riverfest '08 fireworks

I have uploaded a bunch of new photos to my flickr account. It was long overdue, so there are quite a few new photos now.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Andrew flickr ,

ASP.NET MVC and Unobtrusive Ajax with jQuery Part II

September 18th, 2008

In my last post, I introduced this series in which I add Ajax to an ASP.NET MVC application as a progressive enhancement, allowing the site to function without requiring JavaScript, but creating a better user experience for users with JavaScript enabled. In this post, I will discuss the feature I am working on and introduce the base controller and view code as well as introduce a minor change to the initial controller code to add support for Ajax calls/return data without breaking the standard post-based behavior.

The Target Functionality

The functionality that we will be looking at for the purpose of these posts will be a simple content page that allows comments. The comment form will exist on the content page and will call a controller that will then insert a record in the database. Since the comments live on the page with the associated content, the controller will redirect to the view that the form was submitted from (showing the content again, along with the comments). The page will be reloaded, just as you would expect from a typical form submission that redirects following the submission. Once that works, we can update the code to make the form submit via Ajax, at which point we will need to update the page through client script.

The Initial Code

The initial code is a simple controller action which makes a call to a business object that will handle inserting the comment into the database. I will be displaying a code comment as a placeholder for that code since it has very little relevance to the topic at hand.

[AcceptVerbs("POST")]
public ActionResult AddComment(string commentBody, int articleID)
{
//Logic and Database insert code...

//redirect to re-load the page
return RedirectToRoute("Default",
new { controller = "Article",
action = "Show",
id = articleID });
}

At this point, since the View for our content will re-query and display all of the associated comments all that this code needs to do is redirect the user back to the content page and the new comment will be loaded along with the rest of the comments. The above code accomplishes this redirect in a single line of code.

Updating The Controller Action

Now that we have the form in the view successfully submitting its content to the controller action through a post, we need to update the action code to distinguish between a standard post and an ajax-based post in order to return JSON when needed. One of the goals was to make any controller changes minimal. We also want to make sure that none of the business logic changes due to the addition of Ajax. So let’s take a look at the code for the first step:

[AcceptVerbs("POST")]
public ActionResult AddComment(string commentBody, int articleID, string mode)
{
   //Logic and Database insert code...

   //redirect to re-load the page
   return RedirectToRoute("Default",
      new { controller = "Article",
            action = "Show",
            id = articleID });
}

The only change we have made at this point is to add an additional string argument to the method’s signature. This “mode” argument isn’t part of the original form post, and that’s ok. Our form doesn’t need to change. The only time (at this point) the mode value will be passed is when we are making the call from JavaScript. Now we will add a simple check to see if that string has been passed. If it hasn’t been passed, then we know it was a standard post and we will perform the redirect, just like we have been doing:

[AcceptVerbs("POST")]
public ActionResult AddComment(string commentBody, int articleID, string mode)
{
   //Logic and Database insert code...

   if (!string.IsNullOrEmpty(mode) && mode == "ajax")
   {
      //handle json result for ajax call
   }
   else
   {
      //redirect to re-load the page
      return RedirectToRoute("Default",
         new { controller = "Article",
               action = "Show",
               id = articleID });
   }
}

Now all that’s left to do is return JSON formatted data if the mode has been passed. The final version of the controller action is listed below.

[AcceptVerbs("POST")]
public ActionResult AddComment(string commentBody, int articleID, string mode)
{
   //Logic and Database insert code...

   if (!string.IsNullOrEmpty(mode) && mode == "ajax")
   {
      //The comment object is returned after the data insert above
      return this.Json(comment);
   }
   else
   {
      //redirect to re-load the page
      return RedirectToRoute("Default",
         new { controller = "Article",
               action = "Show",
               id = articleID });
   }
}

This code includes a call to the Controller’s Json method (referenced as this.Json) which accepts your data object (in our case, a comment object that was returned from the omitted data insert code) and returns a JsonResult object that can be returned from the controller. The passed object is then made available to your JavaScript when it receives the Ajax result. We will take a closer look at the comment object in the next post, when we add the JavaScript that will trigger the JsonResult object being returned.

This controller action meets our goals of using the same logic regardless of the method that was used to post the form and I think the changes are fairly minimal (again, this is pretty subjective).

Coming Up

We still need to add the jQuery code required to make an Ajax call to the controller and ensure that there is a return value. After we have the code in place to make the call and run the controller code, there will be a couple more posts to explain how to handle the return data and add some other nice UX features for those with JavaScript enabled.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Andrew .NET, ASP.NET, Ajax, JavaScript, MVC, jQuery , , , , ,

ASP.NET MVC and Unobtrusive Ajax with jQuery Part I

September 15th, 2008

I have recently started developing a website using ASP.NET MVC (preview 5). One of the things I love about the MVC framework is the total control I have over my markup. I can keep the HTML clean, use ID values that make sense and won’t change each time the page is rendered and I can add all of my own client-side interactivity using jQuery (without the id mess that web controls create).

One of my goals with this new site is to create a functional site that works and renders in a usable manner even with CSS and JavaScript disabled. In order to do this, I have been creating all of the required interactions using standard get and post operations. The next logical step is to add Ajax functionality as a progressive enhancement using jQuery. Since ASP.NET MVC is still pre-beta, there isn’t a lot of documentation or published best practices with specifics about how to best handle this through the framework. I have read several posts from others with different solutions, they range anywhere from routing hacks (including ajax or html in the url) to seperate views (one standard view and an ajax enabled view). None of the solutions I have found have been what I wanted to do, so I set some goals for how I wanted it to work and through a process of trial and error, I have a solution. Through the next couple of posts, I will outline how I am handling this. I look forward to any feedback (good or bad) and if somebody has a better solution, please let me know.

The Goals

  1. Site should work in an acceptable manner without JavaScript enabled
  2. The same view should handle both Ajax enabled and standard post/get operations
  3. All controller code should be run in either scenario except for returning the ActionResult
  4. Changes to the controller action signature should be minimal and the same approach should work for any controller action (with minimal change)

Some of these goals are no-brainers, it helped to have all of the goals in place to keep myself from creating a massive amount of “Franken-code” in order to get the site working. I also realize that using the word “minimal” when talking about code changes is subjective, so if you don’t think what I have done is minimal, feel free to comment on the posts that contain the code and we can discuss it, please just share something more than “your solution sucks…” that won’t help anybody. And, if you have any other goals that you think I shoudl keep in mind, please let me know. I can’t promise that I’ll be able to attain more than I have already planned for in this series, but if something that I haven’t thought of seems important enough, I will do my best to try to meet the new criteria.

Upcoming Posts

Stay tuned. I have the code worked out for the most part, but it hasn’t been fully implemented, so I will be posting as I make more progress and I have tested enough to feel confident that I will have working code. I’m hoping to get the first post that has any real substance out before the end of the week.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Andrew .NET, ASP.NET, Ajax, JavaScript, MVC, jQuery , , , , ,

Alternating Item Styles In The ASP.NET ListView Control with jQuery

September 15th, 2008

In my last post I demonstrated how you could simply add alternating CSS styles to a ListView control without the need to duplicate your markup in an AlternateItemTemplate. This was accomplished through server-side code using the DataItemIndex to determine which style to apply. This time, we will look at how simple it is to apply the same effect using jQuery on the same simple markup that I used in the last post. I have removed the DataItemIndex related code and we are now left with this markup:

<asp:ListView ID="lvPeople" runat="server" ItemPlaceholderID="plcItem">
   <LayoutTemplate>
      <div id="people">
         <asp:PlaceHolder runat="server" ID="plcItem" />
      </div>
   </LayoutTemplate>
   <ItemTemplate>
      <div>
         First Name: <asp:Label runat="server" ID="lblFirstName" Text='<%# Eval("FirstName") %>' /><br />
         Last Name: <asp:Label runat="server" ID="lblLastName" Text='<%# Eval("LastName") %>' /><br />
         Age: <asp:Label runat="server" ID="lblAge" Text='<%# Eval("Age") %>' />
      </div>
   </ItemTemplate>
</asp:ListView>

With the markup in place, I have added a reference to the jQuery library in my page like so:

<script language="javascript" type="text/javascript" src="jquery-1.2.6.js"></script>

Now all that’s left is to add a little bit of jQuery code and we can apply our alternating css classes.

<script language="javascript" type="text/javascript">
   $(function() {
      $("div#people div")
         .filter(":even").addClass("even")
         .end().filter(":odd").addClass("odd");
   });
</script>

It’s that simple. The code listing above was broken out onto multiple lines, but could just as easily have been written in one single line, I prefer the format above for readability, but that’s just me.

The jQuery code selects all divs that are children of the wrapper div (identified with the “people” id attribute) and runs a filter that only returns the even items. It then adds a css class called “even” to those divs. The end() method then returns scope back to the first selection containing all of the child divs. The second filter runs just like the first, only this one returns the odd items and aplies the “odd” class to those divs.

If you haven’t used jQuery before, I suggest you check it out. It makes selecting items and then manipulating them simple and in a pretty intuitive way (IMHO). If you don’t think it looks easy, try writing code to do this without the aid of a JavaScript library such as jQuery, make it work across browsers and then decide if this way isn’t easier.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Andrew .NET, ASP.NET, JavaScript, jQuery , , ,

Alternating Item Styles In The ASP.NET ListView Control

September 15th, 2008

If you have used the asp.net listview control, you know that you place your output elements in between the ItemTemplate tags. You may or may not have noticed that there is also an AlternateItemTemplate tag that can be used to render every other item differently. This is great when you want to alter the layout of every other item, but if you just want to apply a different CSS class on alternate items, you will be duplicating a lot of markup for a fairly minor change. Well, I have good news, there is an easier way. All you need to do is look at the DataItemIndex for your data item, determine if it is even or odd and apply the appropriate css class. The code is pretty self-explanatory, so here it is:

<asp:ListView ID="lvPeople" runat="server" ItemPlaceholderID="plcItem">
   <LayoutTemplate>
      <div id="people">
         <asp:PlaceHolder runat="server" ID="plcItem" />
      </div>
   </LayoutTemplate>
   <ItemTemplate>
      <div class='<%# Container.DataItemIndex % 2 == 0 ? "even" : "odd" %>'>
         First Name: <asp:Label runat="server" ID="lblFirstName" Text='<%# Eval("FirstName") %>' /><br />
         Last Name: <asp:Label runat="server" ID="lblLastName" Text='<%# Eval("LastName") %>' /><br />
         Age: <asp:Label runat="server" ID="lblAge" Text='<%# Eval("Age") %>' />
      </div>
   </ItemTemplate>
</asp:ListView>

The key is this line of code:

<div class='<%# Container.DataItemIndex % 2 == 0 ? "even" : "odd" %>'>

This allows alternating styles without duplicating your markup, which makes changing the item layout in the future much easier. You could also accomplish this with some javascript (in a line or two using jQuery) but that is a topic for another post.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Andrew .NET, ASP.NET ,