Master-Detail with the GridView, DetailsView and ModalPopup ControlsMatt Berseth

Posted on April 29, 2008 by matt@mattberseth.com.
Categories: ASP.NET, Contributors.

A while back I wrote a post describing how the DetailsView, GridView, UpdatePanel and the AjaxControlToolkit's ModalPopup controls could be used to implement the common Master/Details UI pattern.  I cheated a bit when creating my original example in that I didn't really complete the implementation - the Save button on the popup didn't actually do anything.  Since writing that post I have received a lot of email and a number of people left comments asking me to complete the example - so here it is.  If you plan on reading through this article, I recommend playing around with the demo site to get a feel for how the page works.  All data changes are only persisted to memory, so don't worry about messing up the data set.

Live Demo | Download

image

Scenario

I am sure everyone is pretty familiar with Master/Details style of editing data, but just in case - here is how my page works.  The grid shows 12 rows of customer data.  The far right column in the grid contains a hyperlink that when clicked brings the detail view of the row into focus so the corresponding row can be edited.  The detail view is a popup control and contains a Save and Close buttons.  When close is clicked, the detail popup is dismissed and the user goes back to viewing the main grid.  When they click Save, some simple validation checks are run (all are RequiredFieldValidators for this sample) and the new data values are persisted, and finally the detail popup is dismissed and the main grid is refreshed so that it displays the changes.

Controls

There are quite a few controls that work together for this sample.  Here is a listing of the controls and the role they play.

Control Role
GridView Display the 12 customer rows of data
DetailsView Display the single customer row that is currently being edited
ModalPopupExtender Display the DetailView modally
UpdatePanel Allow the DetailView to be loaded without refreshing the entire page
ObjectDataSource Manage how our UI interacts with the customer data

Customer GridView

The Customer Grid is just a regular GridView.  I have used BoundFields to bind to the data and I am using a TemplateField for rendering the 'Edit' anchor. 

image

When 'Edit' is clicked, I want to show the detail view popup.  To accomplish this I set the CommandName of the 'Edit' button to Select - this will cause the SelectedIndexChanged event to fire on the server.  Inside this event handler, I force the DetailView to databind, passing the datasource it is bound to the ID that corresponds to the row the user clicked.  Finally, I let the UpdatePanel the DetailView is contained in that it needs to update its contents and invoke the Show server side method of my ModalPopupExtender which will cause the popup to be displayed when the partial page is reloaded on the client.

Here are the 2 events handlers that I am using to accomplish this bit of work.  The top event handler fires when 'Edit' is clicked and the explicit call to DataBind forces the DetailView's corresponding ObjectDataSource's Selecting event to fire.  In this handler I use the SelectedIndex of the GridView to fetch the ID the data source needs. 

image

image 

Customer DetailsView

The DetailsView for the individual customer records is also pretty simple - except because I have included RequiredFieldValidators I wasn't able to use the BoundFields and instead I had to explicitly define the EditItemTemplate for each of the fields.

image

Just below the DetailsView, I have 2 buttons that interact with the ModalPopupExtender.  The Close button dismissed the popup without posting back or committing any changes.  The Save button does post back, moves the data out of the DetailsView and back to the ObjectDataSource, hides the ModalPopupExtender and finally causes the main GridView to refresh so it displays the changes.

image

Here is the logic I have wired to the Save button's click handler.

image

Apply a Yellow Fade to the Updated Row in the GridView

And while this has been pretty much nuts and bolds functionality thus far, I couldn't resist trying to spice it up by applying a yellow fade to the row in the main grid that was updated.  To implement this feature, I needed a way to send a bit of information back from the server that let me know what row in the grid was updated.  So my approach was to use the ScriptManager's RegisterDataItem method to accomplish this.  Here is the doc from MSDN:

Sends custom data to a control during partial-page rendering, and indicates whether the data is in JavaScript Object Notation (JSON) format.

Just what I need - so after the Save button is clicked, back in the server side event handler, I call RegisterDataItem and pass the index of the updated row to the GridView.  Then after the partial refresh has occurred back on the client, I extract the row index from the DataItem's collection, use it to find the row that changed and give it a custom CSS class.

So I added the following call to my Save button handler to register the index of the row that was changed.

image

And then added the following JavaScript to my page to track down the corresponding TR element in the rendered table and apply the updated CSS class to the row.

image 

And like magic I get a yellow background applied to the row that was edited.  The background color stays in place for 1.5 seconds then my timeout handler fires and removes it.  A poor man's animation, but the plumbing is in place for me to improve upon.  Below are the screen shots of how it looks.

image

image

That's it.  Enjoy!

Highslide JS .NET Updated (v0.7)Encosia

Posted on by Dave Ward.
Categories: ASP.NET, Contributors.

An update to Highslide JS .NET is available today. I recommend that everyone upgrade, to benefit from the memory leak fixes in the latest Highslide JS.

v0.7 (4/29/2008)

  • Updated embedded Highslide version to 3.3.17.
  • Improved caption rendering, using inline caption divs. This should result in more semantic markup, pairing your captions with your images.
  • Added HighslideManager property: NumberOfImagesToPreload. This allows you to control how many images are automatically preloaded.
  • Added HighslideManager property: FadeInOut. When true, this fades the enlargement in and out as it’s resizing.
  • Added HighslideManager property: RenderScriptInPlace. This allows you to control where on the page the Highslide JS script is inserted in your page.
  • Updated download to include a sample site, to make it a little easier to get up and running quickly.

As always, the latest version is available on the Highslide JS .NET project page.

Originally posted at: Encosia.

NTFS-3G Makes NTFS Partitions Writable [Featured Download]Lifehacker

Posted on by Gina Trapani.
Categories: Contributors.

Mac OS X and Linux: Now that you're dual booting Windows on your Mac, you want to save files to your Windows partition while you're booted up in OS X. By default, NTFS-formatted disks are read-only in OS X, but the NTFS-3G driver makes it writable. Download NTFS-3G, then use the following command to save and edit files on your Boot Camp partition:

sudo mount -t ntfs-3g /dev/disk0s3 /Volumes/Untitled

You can also use the previously mentioned MacFUSE to write to NTFS disks, but while mounting disks over SSH went without a hitch with MacFUSE for me, I had trouble with NTFS disks (though NTFS-3G worked perfectly). The NTFS-3G driver is a free download for Mac and Linux.

NTFS-3G: Stable Read/Write NTFS Driver


CCleaner 2.0 Decrapifies Your PC [Featured Windows Download]Lifehacker

Posted on by Gina Trapani.
Categories: Contributors, Windows.

ccleanerthumb.png Windows only: One of our favorite PC cleansers CCleaner (which stands for "Crap Cleaner") saw an upgrade this week. Since the last time we mentioned CCleaner several new versions have come out; this week's added support for the Firefox 3 beta plus performance improvements and bug fixes. CCleaner scans your PC for unnecessary temporary and log files, cookies, memory dumps, and more and wipes them out at the press of the "Run Cleaner" button. You might be surprised at how much disk space it can recover—in fact, it managed to clear out 1.6GB of crap from my PC. See screenshot evidence after the jump.


CCleaner also includes a registry scanner, startup manager, and Add/Remove Programs area to uninstall applications you don't use anymore. CCleaner 2.0 is a free download for Windows only.

CCleaner [via CyberNet]

Superior Alternatives to Crappy Windows Software [Crapware]Lifehacker

Posted on April 28, 2008 by Gina Trapani.
Categories: Contributors, Windows.


It may be the year 2008, but a whole lot of sucktacular software still rears its ugly head on PC's everywhere, even when better-behaved options are freely available. Whether it's molasses-slow bloatware, shameless adware, anemic default apps, or "Your trial period has expired!" nagware, it's time to replace stinky Windows software with its superior (but lesser-known) alternative. Last week we asked what software you should never install on your PC, and over 200 comments later, you compiled quite a list. Today we're going to take a walk down the Crapware Hall of Shame, point and laugh at the worst offenders, and highlight some better choices. Photo by chelseagirl.

Application to Avoid: Adobe Reader
Indictment: Bloatware
Superior Alternative(s): FoxIt Reader or Sumatra PDF
Notes: There are much worse offenders on this list than Adobe Reader, which has gotten more performant over the years. Keep in mind that Adobe deals with some PDF's (like ones with editable form fields) better than FoxIt. If you don't want to ditch Adobe Reader entirely, here's how to tweak Adobe 8 for speed.


Application to Avoid: AOL Instant Messenger pidginthumb.png
Indictment: One-trick pony with ads included made by a company that holds its customers hostage. (Speaking of, here's how to cancel your AOL account.)
Superior Alternative(s): Digsby or Pidgin or Miranda or Trillian or Meebo
Notes: The moral of the story is you should avoid anything that comes on six zillion free CDs that swamp your apartment building's mailroom.


Application to Avoid: Browser Toolbars (that you didn't seek out yourself)
Indictment: Notorious for hijacking your browser, phoning home with your online activity, taking up precious real estate, and not offering any features you actually want.
Superior Alternative(s): Your browser's built-in search box and a few good bookmarklets
Notes: Don't get us wrong: Not all toolbars are bad, but do beware when they get tacked onto the end of a totally unrelated software installation and you have to opt OUT of them.


Application to Avoid: Internet Explorer (6 and 7)
Indictment: Lacks features any self-respecting modern web browser had two versions ago
Superior Alternative(s): Firefox
Notes: Because IE gloms onto the innards of your operating system so inextricably, you can't truly uninstall it. Just set your system's default browser to Firefox to avoid launching IE ever.


Application to Avoid: iTunes
Indictment: Too controlling, gleefully enforces DRM, can't monitor folders for new music
Superior Alternative(s): foobar200 (more on foobar2000), Songbird, or WinAmp
Notes: We—ok, I—actually like and use iTunes, ever since that time Steve Jobs waved that iPhone over my forehead and chanted. These recommendations only for those with particularly sensitive digital music sensibilities.


Application to Avoid: Java Runtime Environment
Indictment: You ugly and yo' Mama dresses you funny
Superior Alternative(s): None.
Notes: If you want to run a Java app, without the runtime you're SOL. Java, we love the idea of you. Just not the coffee cup staring at us from the system tray.


Application to Avoid: Limewire
Indictment: Where do we start? Haven't launched Limewire since our college days, and don't plan to ever look back
Superior Alternative(s): Frostwire
Notes: Bonus: Frostwire does BitTorrent, too.


Application to Avoid: MSN Messenger
Indictment: Little ugly non-faces with a red X over them plant themselves in your system tray with no obvious way to uninstall or quit it
Superior Alternative(s): Digsby or Pidgin or Miranda or Trillian or Meebo
Notes: Uninstall MSN Messenger by going to the "Add/Remove Windows Components" area in Control Panel's "Add/Remove Programs" area.


Application to Avoid: Nero Suite
Indictment: Costly
Superior Alternative(s): CDBurnerXP
Notes: The free CDBurnerXP may not do everything Nero does, but for the price it does a whole lot.


Application to Avoid: McAfee/Norton/Symantec Anti-Virus
Indictment: Naggy subscription costs after the free trial on your new PC runs out
Superior Alternative(s): AVG or Avast
Notes: See why many readers have ditched their AV software.


Application to Avoid: QuickTime
Indictment: Plants itself in your startup and system tray
Superior Alternative(s): QuickTime Alternative
Notes: While QuickTime doesn't annoy us THAT much, it still annoys us a little—especially since it comes with Apple's Software Update. (See Safari's Honorable Mention, below.)


Application to Avoid: RealPlayer
Indictment: We're still so traumatized about RealPlayer's repeated takeover of our PC back in 2004 we're seeing a special doctor that's killing that part of our memory
Superior Alternative(s): Real Alternative


vlcthumb.pngApplication to Avoid: Windows Media Player
Indictment: WTF interface, chokes on clips in common formats
Superior Alternative(s): VLC


Application to Avoid: WinZip
Indictment: Cost
Superior Alternative(s): 7-Zip or ALZip


Honorable mention: While Apple's Safari web browser for Windows itself is not crappy, Apple's Software Update trying to push it on you completely sucks. Here's how to opt out of installing Safari and stop the nag.

What crappy apps or better alternatives did we miss? Did we wrongly accuse one of your favorites? Let us know in the comments.

Gina Trapani, the editor of Lifehacker, still hasn't forgiven RealPlayer. Her weekly feature, Geek to Live, appears every Monday on Lifehacker. Subscribe to the Geek to Live feed to get new installments in your newsreader.