Posts

Det. Eddie Ibarra -- Hero of the Week

Det. Eddie Ibarra is my hero of the week. Because he solved a homicide in the First 48? No. Because he's a Steelers fan living in Dallas. He was featured on the show the other night and his cube was covered in Steelers stuff. There was even a picture of his kid in a Big Ben jersey. Way to go Eddie!!!! How long is it until the first game.

Easy Way To Maintain Div Scroll Position On Postback

There are numerous ways to maintain scroll position on a postback that all involve javascript coding. Unfortuantely, it always seems like they don't work in the situation I need. Well, the other day, I found a solution that had been right in front of my nose. I was working on a page where I wanted a list of people on the left and the details for the selected person on the right. The list was inside a scrolling div so they'd be able to scroll the list to find the individual.  Everything was wrapped in an UpdatePanel  and I had everything set up right. However, when a postback occurred -- boom -- back to the top of the div. My solution was two UpdatePanels. One inside my scrolling div and the other holding the DetailsView. The UpdateMode is set to Always for both so when the update fires in one, it also fires in the other. Since UpdatePanel is inside the scolling div, the div (and its current scroll position don't update). Viola, a scrolling div that maintains position...

Custom Classes and LINQ To SQL Group By

Image
I spent a good part of my morning trying to get LTS to return my custom class as a result of a group by instead of an anonymous type. Most of the samples I found on the web for Group By returned anonymous types and the ones that didn't were from early versions and I couldn't get them to work. The problem I was having was getting the column I was grouping on mapped. I created a class called DescriptionCounts that had two properties Description (string) and Count (integer). The following code will correctly map a group by query to this class. Dim i = From b In dc.Barriers _ Group By b.BarrierType.Description Into g = Group _ Select New DescriptionCounts _ With {.Description = Description, .Count = g.Count} The main thing to notice is that when the Description property gets mapped, it is mapped to a variable named Description (.Description = Description -- notice that there is no prefix) and not to a property of b. All of the aggregate functions require...

LINQ To SQL Attach

The Attach method allows updating with a disconnected object that has been updated. The easiest version to use is: Public Sub UpdateCustomer(updatedCustomer As Customer)    Dim dc As New MyDataContext()    dc.Customers.Attach(updatedCustomer, True)    dc.SubmitChanges End Sub The only problem is that this generates a SQL statement that updates all columns rather than just the on that has changed. In other words, we used a little extra bandwidth. The reason this happens is because when we disconnected the object, we lost all the built in change tracking provided by LINQ (for now). Option 2 is to get a new copy of the object and update it. Public Sub UpdateCustomer(updatedCustomer as customer)   Dim dc as New MyDataContext   Dim originalCustomer as Customer = from c in     dc.Customers Where c.PrimaryKey =     updatedCustomer.PrimaryKey   originalCustomer.CustomerName = ...

Visual Studio 2008 & SPAN tags

Visual Studio doesn't seem to like SPAN tags. I've already reported a bug where it adds duplicates SPAN tags to templated fields in a GridView or DetailsView that is within a span tags. Now, it's moving my span tags around. I had two span tags to define left and right columns with inline-block. They were contained within the same div. Somehow, VS decided that the left span belonged to the div above and moved it all on it's own. If it keeps happening, I'll see if I can narrow the circumstances down and get a bug report filed. Technorati Tags: Visual Studio 2008 , SPAN , Designer

VS 2008 GridView Rendering Bug

Found an annoying bug in VS today. If you have a GridView contained in a Span tag on a ContentPage and edit the fields, VS will add span tags around the fields you change. Of course, when your done making your changes and click OK, you'll get a rendering error. Simply edit the source and remove the spurious span tags. Technorati Tags: GridView , Visual Studio 2008 , Span , ContentPage , MasterPage

LINQ To SQL OnValidate doesn't fire

Technorati Tags: LINQ To SQL I spent half an hour tracking this down today and couldn't find it based a google search of the blog title. So.....If your OnValidate code isn't firing in your LINQ to SQL, your probably working with an out-of-date signature. Somewhere between Beta 2 and RTM, they snuck in a slight change by adding a parameter to indicate what kicked off the method. Make your signature similar to: Private Sub OnValidate(ByVal action as ChangeAction) The ChangeAction enumeration values are Insert, Update, Delete and None. So if you need special code for the insert versus the update, you can code an IF statement appropriately. You can find all of the breaking changes here .