Passing and Accessing DataBinder Container DataItems

When fielding a few questions on the ASP.Net Forums I ran across a question that I’d recently read about going through the ASP.Net 2.0 Wrox book. The question was how do I access the row values from a databound grid without having access to the original data source. The person then went on to ask whether they’d be able to pass the DataBinder class object to the code behind to have access to the static Eval() method for the entire row of data.

Normally in the markup you see most of the databound code examples will have a function that accepts an input value that is called from the markup, passed to the code-behind, and then the code behind will output a formatted value back to the markup. It works well for situations where you need to calculate values quickly without the original data source, or to quickly format values for display purposes on databinding the control to a datasource.

 

Passing a Single Eval DataItem

ASPX

<%# GetTotalValue(Eval("ColumnName")) %>

CS

protected int GetTotalValue(object total)
{
     int value = 0;

     int.TryParse(Convert.ToString(total), out value);

     return value;
}
 

In cases where multiple row values need to be accessible without having to pass each value directly one could simply access the databound row from the code-behind during the binding of the data control. In this case we still have the markup call to the code-behind as seen in the ASPX section below. This time we’re not passing any value(s), but instead we’ll just call them as we need them on the code-behind. Yes, it’s that simple. As you can see below we simply call to the DataBinder.Eval static function, pass in the data container (exposed by the Page,) and then simply supply the name of the column from the datasource we want. This is not limited to a single column, but only to a single row of data at a time.

 

Accessing Multiple DataItems 

ASPX

<%# GetTotalValue() %>

CS

protected int GetTotalValue()
{
      int value = 0;

      int.TryParse(Convert.ToString(DataBinder.Eval(Page.GetDataItem(), "ColumnName")), out value);

      return value;
}
 

The reason this is limited to a single row is that we’re only able to access these values during data binding event, which is indcated per the ‘<%#’ on the markup side indicating that this function will only be called when the form is binding. Each row will call the same function outputting the unique formatting of the columns or calculations being performed on the code-behind calls. There is no need to try to pass the DataBinder, pass the datacontainer, or anything of the sort because it’s already available to us. Now keep in mind that you can’t call the GetTotalValue() anytime you’d like as this function will only work during the the databound event of the control.

6. January 2009 13:14 by Rampidbyter | Comments (0) | Permalink

Linksys Wireless Router Problem – Dropping Connection

linksys

Frustrating! That is the one word I'd use to describe the problem i’ve been having lately. First the wireless router is connected to a wired only Linksys business class router, and the wireless router is merely to provide connectivity throughout the house. There is typically at most two computers connecting to the wireless router. This is a new addition to the network, and was a replacement for my Linksys access point that i had blamed for the initial problem.

I have a folder shared on my desktop upstairs that is connected to the wired business class Linksys network router. The Linksys wireless router is set as a router and is on the same IP schema that shares the local network. I can connect just fine to the shared folder, run music, and play movies from the PC without any problems from the desktop from the wireless share. I can do all this while others are playing a LAN game of Star Craft, and all the while I'm listening to Pandora. So the connection is fine, no real latency, and everything seems fine.

The problem is when i start transferring large files (3-300 MB) to and from the shared folder, or even from within a remote desktop connection. The connection to the network then slows shortly after starting the transfer, becomes unresponsive, and eventually I'm disconnected from the wireless network. I’ve checked every router setting, I've upgraded firmware, and even went ahead and updated the intrusion protection files. I had the initial problem with my access point, and even after purchasing an actual wireless router still am experiencing connection loss on trying to transfer large files.

I’ve done some research to see if anyone else has experienced similar problems, and found one to many similar experiences. From what I've found it seems that when starting to transfer a large data file the router/access point is overheating because of poor air circulation and overhead imposed on the processing capacity to move large files. I even found one guy who cut the bottom out from the router, installed an 90mm fan, and a thermal heat sink unit to the router to keep from experiencing data loss. I may consider doing this in the future, and I'm really surprised that this would be the cause since I'd think a lot of people use the wireless router to move files back and forth from once pc to another over a wireless connection. It only comes from transferring one pc to another, and not from actually downloading large files from the internet. I downloaded SDKs, DDKs, IDE’s, and had absolutely no problems downloading files 500mb-1gig.

5. January 2009 15:51 by Rampidbyter | Comments (0) | Permalink

The Living Dead

516VUMu5cQL._SS500_ I just finished reading the collection of short stories bundled in the book ‘The Living Dead.’ Considering all the books i normally read are technical in nature i bought this book as something to skim in my off time. I bought it really on a whim at Borders while passing through the horror section on my way to checkout with my ‘Dirty Japanese Sayings’ book (that’s a whole other story.) I saw this book and for whatever reason picked it up and headed up to the counter. I guess there is something to be said for disposable income when i can just grab whatever tickles my fancy, but I've always valued reading even if it’s about zombies. So i figured it would at least be something i could hook into when i was bored.

Well, i started reading the first few pages after i got the book home. I became so enthralled by the stories that i couldn’t seem to put it down, and actually found the .Net 3.5 book i’ve been reading was the one that got shelved till i finished this new book. The book is absolutely fantastic because the stories don’t build on each other but present zombies in about every aspect you can image. Zombies are portrayed as being servants, work tools, physical representation of our actions/inactions, carefree simpletons, and of course the mindless killing machines we often imagine upon hearing the the word zombie.

Each story is as different as the next so you’re never reading the same type of story one after the other. Each story is as varied as the authors who pinned them. If you’re into reading stories of zombies then the obvious choice is to pick up this book and add it to your collection. Even if you’re not that into zombies i’d highly recommend this book simply to see the full gambit that zombies are portrayed. I do have to say that some of the stories have a sexual connotation so do at least make sure the reader is at least of age to read this collection.

5. January 2009 14:13 by Rampidbyter | Comments (0) | Permalink

Schwinn 230 Exercise Bike

schwinn_230_recumbent_exercise_bike  Those of you who know me, know that I'm a bigger guy. I was a big kid, tall and chunky, then I lost a lot of weight and was a tall string bean, and that brings me to the current shape. I'm tall but I'm definitely not a slender guy. I've lost weight here and there to the point where I needed knee surgery thanks in part to my treadmill, which I'll give it's fair credit for having caused my meniscus tear. I went to a fitness club with a friend here and there for a period of a close to half a year before conflicting schedules caused that to deteriorate, and being one to not keep up with things unless held accountable did not pick up the slack.

That brings me to the recent Christmas gift' that I gave to my wife and I. It was a bit pricey (in and around $500) but the Schwinn 230 exercise bike has been a great gift, to me, and I am using it everyday for 60 minutes a pop. In 60 minutes I've been burning off 630 calories and getting a really good burn in my legs. Unfortunately, this has brought attention to the fact that my knee surgery has definitely not fixed my problem. I say it was a great gift to me because when I told my wife I was giving her the present earlier she was excited, up until the point where she helped me carry it off the back of the truck inside, and then her enthusiasm dimmed quicker than a light in a power outage. That coupled with the fact that when asked by family about the bike and the sudden appearance was shortly answered by her "he thinks i'm fat" I had to give her another gift. A Nintendo DS with the Brain Age game. Its hard to win with women, she probably thinks I'm eluding to her being dumb now.

Anyway, the bike has been great. The seat is comfortable even after an hour of using one of the three handy bike programs on level 10. It goes to level 16, which for most people is more than enough unless you're training for the Olympics or biking across America or something. The console on the bike is relatively easy to use, offers a menu to see how many calories have been burned, calculate your BMI, and to keep up on progress being made while biking. It has a built in heart rate monitor so you can know with a reasonable assurance whether you're in the target heart rate for your body to burn calories the best.

There are of course your standard pros and cons associated with any product. I'll try to list them off as best as i can below.

Pros

  1. Built with stability in mind with adjustable screws for platform legs to stabilize the bike.
  2. Many programmed programs to choose from to exercise with from 'riding in the park' to 'endurance' resistance settings.
  3. Built-in heart rate monitor
  4. Displays speed, distance, timing, and calories burned during workout.
  5. Manually adjustable resistance settings to make any workout more difficult.
  6. Sliding seat to target different areas of the leg.

 

Cons

  1. The turn screw on the sliding seat isn't easily adjusted while actually using the bike.
  2. Seat squeaks a bit when really getting into the riding.
  3. On the console is a small metal hooked front to hold things in. I hit my knee on it and left a good cut on my knee. I mean really what is this for? You can't rest a book on it, that'd be a nice addition, and it's just kind of there so if your knee comes way up it can hit it.
  4. The bike has a water bottle holder that is completely horizontal and under the front left side of the seat. Utterly and completely useless for all purposes.
  5. When assembling the bike connecting the circuitry in the neck of the machine is a pain. The display panel circuitry/power cord is long and taunt so it makes it overly difficult to shove back into the tube. Also the assembly instructions neglect to mention that some parts of the bike are already assembled and must be disassembled to assemble the bike.

 

Overall I'd give the bike a B+. It's worth the purchase, a little pricey, but the ride is comfortable without being too excessively bogged down with programs/components that aren't necessary. A fan would be nice on this model, and a real cup holder would be nice. They may have added that on newer machines, but if you're looking for a good workout on something that will burn calories without tearing cartilage this is a good investment.

4. January 2009 13:36 by Rampidbyter | Comments (0) | Permalink

Pandora Radio (Free Online Radio)

pandoraradio I'm a geek, no question, and I listen to a lot of music. Really i can't imagine a day going by where I'm not listening to some form of music while I'm working out, relaxing, or while I'm toiling at work. It started a long time ago while i was working in my first programming position at SDRC in 2000. I began bringing in my personal laptop with a limited selection of music in MP3 format from the days of Napster not being a corporate unit. I'm not admitting to anything, just saying I had a few songs to listen to.

Since that time I've transitioned from downloading songs to a laptop, listening to radio FM stations, using a Zen Micro Photo MP3 player, an iPod Nano after the Zen died, and now i have Pandora Radio. I use Pandora almost exclusively at home, work, or even on my smart phone. I'm even tempted to hook up a computer system in the car to just use Pandora in the car stereo for long trips. Yes, i have a pocket PC i could use, but come on a computer in the car is awesome. It's become an integrated part of my life where I can listen to genre's i like, artists, and I get the advantage of hearing new music from bands i'd never known existed. I went from Weird Al to The Trucks, Freezepop, Gary Jules, and many more stations waiting to explore. If you haven't tried it, go try it, it's free, and it's incredibly more personalized than your typical top 40 stations you get with most online radio stations.

4. January 2009 08:34 by Rampidbyter | Comments (0) | Permalink

Happy New Year (2009)

I just wanted to wish anyone who reads this a Happy New Year and a blessed 2009. With that in mind i hope any new years resolutions that were made are able to be kept. I made a big one this year and I hope I'll be able to stick with it and make sure it comes to fruition.

1. January 2009 05:42 by Rampidbyter | Comments (0) | Permalink

Windows Remote Desktop Port Number Changer

I was setting up my new laptop this morning and I then started to get into configuring port forwarding on my router. Because this computer is becoming another ad-hoc development machine i decided to add it to the list of PC's i have that are able to be used remotely. To do this i needed to change the default port from 3389 to a custom port number. I again went through the hassle of looking on-line for a site that had the registry path to the terminal services RDP port number setting. It was at this point that either my lazy bone or my uber programming sense kicked in and i made a quick utility to use whenever i need to set the port number again. Thus saving me the hassle of again looking up the registry path, and then skimming through the registry hive looking for the setting using RegEdit.

Here is the code to a quick Console application program i wrote that can be used through command line argument or via standard command line interface.

   1:  using System;
   2:  using Microsoft.Win32;
   3:   
   4:  namespace RemotePortChanger
   5:  {
   6:      class Program
   7:      {
   8:          static void Main(string[] args)
   9:          {
  10:              int portNumber = 3389;
  11:   
  12:              try
  13:              {
  14:                  if (args.Length > 0)
  15:                  {
  16:                      int.TryParse(args[0], out portNumber);
  17:   
  18:                      SetPort(portNumber);
  19:                  }
  20:                  else
  21:                  {
  22:                      string input = string.Empty;
  23:   
  24:                      Console.WriteLine("Remote Desktop Port: " + GetPort());
  25:                      Console.Write("Enter the new port number: ");
  26:                      
  27:                      input = Console.ReadLine();
  28:   
  29:                      int.TryParse(input, out portNumber);
  30:   
  31:                      SetPort(portNumber);
  32:   
  33:                      Console.WriteLine("Port is now " + GetPort() + " press any key to exit.");
  34:                      Console.Read();
  35:                  }
  36:              }
  37:              catch (Exception ex)
  38:              {
  39:                  Console.WriteLine("Error has occured - " + ex.Message);
  40:              }
  41:          }
  42:   
  43:          private static void SetPort(object portNumber)
  44:          {
  45:              RegistryKey key;
  46:   
  47:              key = Registry.LocalMachine;
  48:              key = key.OpenSubKey(@"System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp", true);
  49:              key.SetValue("PortNumber", portNumber);
  50:              key.Close();
  51:          }
  52:   
  53:          private static int GetPort()
  54:          {
  55:              RegistryKey key;
  56:              int portNumber = 0;
  57:   
  58:              key = Registry.LocalMachine;
  59:              key = key.OpenSubKey(@"System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp");
  60:              portNumber = Convert.ToInt32(key.GetValue("PortNumber"));
  61:   
  62:              return portNumber;
  63:          }
  64:      }
  65:  }
28. December 2008 16:44 by Rampidbyter | Comments (0) | Permalink

CCleaner - A must have Windows utility

While the name may be a little off the cuff i have to say CCleaner (crap cleaner) has been a very nice utility. Recently my step-brother acquired yet another virus on his laptop that like most malware utilities installed itself within one of this temp folders. I used the standard assortment of Avast, Spy-bot, Ad-aware, and now CCleaner to help get to those hard to reach temporary file locations. When running the typical assortment of anti-viral utilities the hardest thing to do is to validate that the malware/virus has been removed from all local directories. On top of that trying to locate the registry entries to the now hopefully removed files. With CCleaner the application is able to identify registry file path references that are no longer valid to be removed, among other things, and remove them within about 30 seconds. Not to mention it cleans out the contents of almost every temp file location on the system to help prevent reinstallation of the bad-ware.

This ability to remove both registry and file temp files helps ensure that when running Spy-bot, Ad-aware, and Avast that when the actual files are found then removed that nothing remains. This is not a 100% solution for removing malware or viruses but it sure helps. Running your typical virus scanner or anti-malware application can take anywhere from 10 minutes to 3 hours. With CCleaner you're able to run the application flat-out or use the analysis function to check the system for each file to be removed. The best part is it takes just mere seconds to run a complete check. In the world of waiting and waiting for a scan to complete for most applications the near instant cleaning capability is very refreshing.

28. December 2008 16:34 by Rampidbyter | Comments (0) | Permalink

Calendar

<<  January 2009  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

RecentPosts