CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Eric Wise

Business & .NET

June 2004 - Posts

  • User Defined Grid Layouts

    The challenge: Allow users to define the columns shown and order for datagrid displays in ASP .NET webpages.  Here is my first stab at a solution.

    I'm going to create a class object called Employer, with some text fields, a true/false to be displayed as a checkbox, a hyperlink on the company name, and an image path (just so we can cover several different types of columns in one example).  I am not going to post the class layout, just note that the properties in the class are as follows:

    • Type
    • CompanyName (hyperlink)
    • Length
    • Position
    • Phone
    • Supervisor
    • ImagePath (image)
    • IsChecked (checkbox)

    So the first thing I did was write an xml file that would specificy the order of the columns, and have attributes defining what property on the employer object belongs in each column.  (This will be generated through a config interface in the future, but for now I wrote it by hand)

    <?xml version="1.0" encoding="utf-8" ?>

    <Columns>

    <Column headerText="Type" type="Label" bindTo="Type"/>

    <Column headerText="CompanyName" type="HyperLink" linkText="CompanyName" navURL="editPage" target="_blank"/>

    <Column headerText="Length" type="Label" bindTo="Length"/>

    <Column headerText="Position" type="Label" bindTo="Position"/>

    <Column headerText="Main Phone" type="Label" bindTo="MainPhone"/>

    <Column headerText="Supervisor" type="Label" bindTo="Supervisor"/>

    <Column headerText="Image" type="Image" bindTo="ImagePath"/>

    <Column headerText="Check" type="CheckBox" bindTo="isChecked"/>

    </Columns>

     

    So now in my .aspx page I'm going to instantiate my employer object, read the xml layout file, build the datagrid programatically from the xml layout, add it to the page, and bind it.  (For the purposes of this example I put default values in my employer object and just added a few of them to an arraylist and bound the arraylist to the grid).  Here is the .aspx code:

    Protected emp As New Employer

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim dgr As New System.Web.UI.WebControls.DataGrid

    Dim doc As New System.Xml.XmlDocument

    doc.Load("C:\Dev\StreamLend.Net\CoreGUI\XMLFiles\XMLFile1.xml")

    Dim columnNodeList As System.Xml.XmlNodeList = doc.SelectNodes("//Columns/Column")

    Dim columnNode As System.Xml.XmlNode

    For Each columnNode In columnNodeList

    Dim dgrCol As System.Web.UI.WebControls.DataGridColumn

    Select Case (columnNode.Attributes.GetNamedItem("type").Value.ToUpper)

    Case "LABEL"

    Dim bCol As New System.Web.UI.WebControls.BoundColumn

    bCol.DataField = columnNode.Attributes.GetNamedItem("bindTo").Value

    dgrCol = bCol

    Case "HYPERLINK"

    Dim hCol As New System.Web.UI.WebControls.HyperLinkColumn

    hCol.DataTextField = columnNode.Attributes.GetNamedItem("linkText").Value

    hCol.NavigateUrl = columnNode.Attributes.GetNamedItem("navURL").Value

    hCol.Target = columnNode.Attributes.GetNamedItem("target").Value

    dgrCol = hCol

    Case "CHECKBOX"

    Dim tCol As New System.Web.UI.WebControls.TemplateColumn

    tCol.ItemTemplate = New DataGridCheckBoxColumn(emp)

    dgrCol = tCol

    Case "IMAGE"

    Dim tCol As New System.Web.UI.WebControls.TemplateColumn

    tCol.ItemTemplate = New DataGridImageColumn(emp)

    dgrCol = tCol

    End Select

    dgrCol.HeaderText = columnNode.Attributes.GetNamedItem("headerText").Value

    dgr.Columns.Add(dgrCol)

    Next

    'Build Arraylist and bind grid

    emp = New Employer

    Dim employers As New ArrayList

    employers.Add(emp)

    employers.Add(emp)

    employers.Add(emp)

    employers.Add(emp)

    dgr.AutoGenerateColumns = False

    dgr.Width = Unit.Percentage(100)

    dgr.DataSource = employers

    dgr.DataBind()

    page.Controls.Add(dgr)

    End Sub

    Public Class DataGridCheckBoxColumn

    Implements System.web.UI.ITemplate

    Dim mContainer As Object

    Dim mBindTo As String

    Public Sub New(ByVal Container As Object)

    mContainer = Container

    End Sub

    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn

    Dim chkbox As New System.Web.UI.WebControls.CheckBox

    chkbox.Checked = DataBinder.Eval(mContainer, "isChecked")

    chkbox.ID = "chk1"

    container.Controls.Add(chkbox)

    End Sub

    End Class

    Public Class DataGridImageColumn

    Implements System.web.UI.ITemplate

    Dim mContainer As Object

    Public Sub New(ByVal Container As Object)

    mContainer = Container

    End Sub

    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn

    Dim img As New System.Web.UI.WebControls.Image

    img.ImageUrl = "Images/" & DataBinder.Eval(mContainer, "ImagePath")

    img.ID = "img1"

    container.Controls.Add(img)

    End Sub

    End Class

    Feedback and questions welcome!

  • Netmeeting

    Being it's free and all.  Anyone know how I could get netmeeting to automatically enable the desktop sharing option so that I could remotely administer a machine without having to have a user say “yeah, go ahead”?

    Seems like this would be a much cheaper alternative to pcanywhere

  • Hosting services (dedicated)

    Anyone have any recommendations for dedicated server solutions?  I tend to hear good things about Rackspace but I think I'm technically competant enough to not need a fully managed solution.  I've been glancing at some offerings from Hostway and Serverbeach, but haven't heard much about them good or bad.

    I recently signed up for the 1and1 ms developer package which gives you a slot for asp.net development and a small sql server space for $19.99 a month.  I'm pretty disappointed in it, the sql server tool is really really bad and I haven't been able to get any asp pages working yet.

  • Bought a laptop this weekend

    Bestbuy was running 18 months same as cash on laptops.  I picked up a Compaq, athlon xp 2800, 512mb RAM, 40GB hard drive for $1150 with a $300 mail-in rebate.  That's a pretty decent laptop for the price!  I plan on using it for sales presentations and product demos.  The geek in me wants to upgrade it to 1gb ram, but the realist says I don't need it for what I'm using it for.  We'll see who wins that battle.  =)

    First thing I did when I got it home was blow the operating system away.  Man I hate all that garbage that the big vendors pre-load on your pc.  Partitioned the drive, installed win xp pro, then started the long process of installing software.

    I had quite a fight with visual studio.  The oddest thing happened.  I had installed McAfee virus scan and then was installing visual studio 2k3 (it's a no-no to install it while virus scan is running but it was late and I forgot).  Sure enough, virus scan caused the install to fail.  The rollback failed, and I couldn't restart the install because of some error that popped up (late at night, don't remember).  So I do a system restore and try to start again... nothing, wouldn't install.

    So now it's really late and I'm pretty irritated so I decide to just blow the machine away again and reinstall visual studio first.  Well now the hard drive won't format ntfs, kept getting to 100% then saying there was an error, drive might be bad, whatever.  Now I'm really mad and tired to boot.  But being the geek I am, I couldn't sleep knowing that my new baby was out there broken.  So I tried to format fat 32 on the system partition, it worked.  windows xp installed, I booted it into windows, used the command prompt tool to change the fat32 to ntfs (convert c: /fs:ntfs) and long story short got everything installing properly.

    What a pain in the arse though.  I still don't know how a failed VS 2003 install could hose up the system so badly...

  • Leap of Faith

    So I'm sitting here at my full time job pondering on my next steps.  It's no secret that I have been in the process of launching my own business, and with my full time job sucking up so much of my time I haven't been able to apply the amount of time I'd like to the business.

    Interestingly enough I had a recruiter from IP Logic offer me a 3-4 month contracting gig for a pay rate that nearly doubles my salary.  I met with the client and I think I'd get along just fine with their organization.  It's also full scale vb .net / asp .net which would be preferable to the work I've been doing here so far (you've all seen me gripe on this blog about the FoxPro stuff I've been stuck with).

    3-4 months, more flexible time for starting my business, and they do provide benefits while I'm contracting.  I think it would also motivate me business-wise if I knew that in 3-4 months I might not have any income for a short time.  (Though I really don't fear being out of work, I have almost the maximum possible .net experience and give a great interview, never been out of work more than a month before even with the economy).

    So yeah, I'm about 90% decided that I will take the contract gig.

    Also thanks for the responses in my previous post about seeking my first customer.  I glanced at Amazon for the book "Get Clients Now" recommended by Mr. Livengood and it seems interesting/got really good reviews.  I will likely pick that up this week since I'll be vacationing in the Poconos this weekend and will need something to read.

    Everyone keeps asking exactly what my business does as well since I tend to throw the term service around yet I'm a software developer.  Basically I'm going to offer some hosted asp .net applications for a subscription fee (Also planning on selling a source-included version to companies that have the server tech to handle it, then sell them customization/consulting services.  First I have to get the hosted stuff up and clean up my code a little.)  I'll probably try to do some consulting gigs on the side for a while as well until I get enough customers to be self-sufficient (the business plan is saying 20 or so customers and I can work full time for the business).

  • Getting the full name from Active Directory

    So we're working on getting a user's full name out of Active Directory services for headers in our webpages. Basically we just want to say "Welcome |your name|" somewhere in the header.

    We built and tested a class that seemed to work fine, here's the code snippet:

    public class User
    {
         string loginName;
         string fullName;

         public User(string LoginName)
         {
              loginName = LoginName;
              fullName = GetDirectoryServiceProperty(loginName, "Name");
         }

         static string GetDirectoryServiceProperty(string ObjectName, string PropertyName)
         {
              DirectoryEntry de = new DirectoryEntry("LDAP://yourcompany.com");
              DirectorySearcher aSearcher = new DirectorySearcher(de);
              StringBuilder filter = new StringBuilder();

              filter.AppendFormat("(anr={0})", ObjectName);
              aSearcher.Filter = filter.ToString();
              SearchResult sr = aSearcher.FindOne();

              if (sr == null) 
              {
                   throw new NullReferenceException("No such directory entry exists");
              }

              DirectoryEntry directoryObject = sr.GetDirectoryEntry();

              return (string)directoryObject.Properties[PropertyName].Value;
         }

         public string LoginName { get { return loginName;} }
         public string FullName { get { return fullName; } }
    }

    So we go ahead and deploy this to our web application, which is using windows authentication... and it gives us a null exception.

    We poke around a bit and discover even though we were using windows authentication and the Context.User.Identity.Name property was returning a user name, the ASPNET account was the one trying to run the LDAP service which since ASPNET isn't a member of the domain isn't allowed.

    Long story short, we added identity impersonate="true" to our web.config and everything started working fine.

  • .netcharting tool

    www.dotnetcharting.com

    I don't have a very warm track record with third party tools. In general, I have found most of them to be pretty complex to use and time consuming to learn to the point where it isn't worth me pursuing them.

    So I downloaded the developer trial of dotnetcharting's component with pretty low expectations...

    I WAS WRONG.

    I had this tool installed and a simple sample chart up and running correctly in less than 20 minutes. Very impressive.  It even has a drill in feature.  I did a very very basic drill in, so I'm not sure how customizable or complex you can get but the basic drill worked well.

    I plan on purchasing a license for this for my business website once I find that first customer.  (developer edition is free)

  • Trying to make that first sale

    So my little home business project is off the ground and ready for that first customer.  I sort of fear sales though, and I know that the Google adword campaign I've launched probably won't be enough to bring in some customers.

    So now I'm thinking about doing some pitching of my services locally.  Not overly sure of how to do the approach though.  I really hate the idea of cold-calling etc, but I'm having trouble thinking of ways to get someone to listen to my few minute marketing presentation without doing it.

    Any sales types out there?  How would you go about the initial launch of an IT service?

  • VB Roadshow + Reverse User Group

    Here's my official VB Roadshow report from last night:

    First I did the reverse user group thing.  A few developers were picked to represent the local community to give feedback to the Microsoft representatives.  A few things we talked about:

    - I want it to be an IDE feature that I can take a database table from my server explorer, drag it onto a blank class, and have it generate properties and private variables for each of the fields in the table.

    - Some guys where talking about having some disatisfaction with deployment in the enterprise, particularily being able to see which files are actually going to be nuked when you copy it out over the old version.  I've never had any problems with this so I didn't have much to add.

    - We talked a lot about the VB "Stigma" ie that it's a toy language, and that c# developers get more prestige and pay.  Everyone who knows anything about .NET knows that this is silly since they compile the same.  But hey, as the Microsoft representative put it: "If a client insists on paying you more to write code in C#, you are morally obligated to take their money".  =)


    After the reverse user group the actual show started, there were a lot of people there!  Here's what we talked about:

    - The My namespace absolutely rocks.  My is basically a vb thing that allows you to access commonly used pc functions (printing, pulling user names, getting config values, and alot more)  It makes me wobble now in my recent switch to c#.

    - There are some power pack tools coming out for windows forms.  Basically designed to give you a more xp-ish feel.  Not really of interest to me as a web developer though they did look nice.  Also had some tablet pc controls for handwriting.  Again, they were nice, but not really valuable for what I do.

    - Generics are pretty cool, they demo'd how to make a collection out of your custom class with one line of code.

    - You can bind a form to an object (class) now, then all of the properties exposed by the class appear in a sidebar on the IDE, you can then set the control type for displaying the property (label, textbox, etc) and drag and drop the properties onto a form where they automatically wire up.  This was neat but I wonder how it would behave if one of your properties was a collection of another object?  Hopefully it will be smart enough to handle that and drill all the way into that object collection.

    - You can still interact with office, (the showed Excel).  This hasn't changed all that much, they made it a little easier.  Someone in the audience asked about working with excel in a web environment and the presenter said you could do it.  I had to speak up and point out that running excel on your webserver is generally a bad thing, and that you'd be better off creating a writer, sucking up the html from your datagrid, changing the mime type to excel, then spewing the html into it.  Excel will render cells just like the datagrid and it forces the client to use excel, not the server.

    - Demo of the 2005 IDE.  It's gotten alot nicer, I really liked how much cleaner alot of the configuration stuff was.  Too much of that to cover here, when the next beta comes out try it for yourself.  They did show a nice little control name editing feature.  The entire form's controls all popped up little labels with their names in them in this mode, you could tab through the form and change the names of the controls (much preferable to click, change property, click, change property for those of us who are quick with the keyboard)

    - There are some new pre-compiling features (like warnings uninitialized variables).  Nice touch.

    - Edit and continue is back, yay!

    All in all the speakers were very good, better than most of the other MS events I've attended locally.

  • Dumbest thing I've ever heard

    Here's a fun one to wrap your brain around.

    I have a certain female friend, we'll call her jenn for the purposes of this story.  A few years ago when I was in college living with several roommates in an apartment, my one roommate had some... plantlife growing in his closet.  Because they were in the closet, he needed to set up some lamps that were on an automatic timer.

    So one day Jenn is visiting us, and she finds the plants b/c the lamps were on at the time and she though he had left his closet light on.  Now she had never seen a closet project like this before, and she was asking us about the lamps, specifically what would happen if he forgot to turn them off... conversation is as follows:

    Me : “He doesn't have to remember to turn them off, they have a 24 hour timer, they run for however long he tells them to then shut off, then turn on the next day at the appointed time.”

    Jenn : “oh”

    At this point Jenn gets a really puzzled look on her face.  Then she says it, the dumbest thing I've ever heard:

    Jenn : “If there are an even number of hours in a day, and an odd number of days in the week, how does that timer stay accurate?”

    *jaw drops, brain tumor develops, I pass out for an hour*

    To this day I still can't figure out what chain of thoughts led to that question/conclusion.

  • VB Roadshow Tonight in Albany, NY

    I'll be attending this event and I'll also be attending a reverse-user group before the event where a group of leading area developers will get some face time with some members of the vb team.

    I'll try to filter out the marketing goo from the subjects of real value and post tomorrow.

  • We are servants!

    I decided that for today's post I would write about a concern I've had with every company that I've worked for in IT.

    Arrogance, plain and simple.  So many IT workers seem to have this holier-than-thou attitude toward their users.  (SNL even has a skit about an obnoxious IT guy)  Users are clueless, they are a pain in my ass, they don't understand how anything works, etc etc etc.  This attitude is apparent to the end user, who doesn't generally challenge the IT worker because:

    1. They really don't understand.
    2. They need the services of the IT worker.
    3. If someone approaches you with an arrogant attitude, you won't be interested in learning anything anyway.

    I'd like to remind everyone that we in IT are servants!  The only reason we exist is to make the company run better and a major part of that job is making sure the end users know the very basic fundamentals of why things are, and what technology is capable of to make things better.  This is especially true in programming and design.  If you make your end users feel uncomfortable discussing things with you, you will end up missing out on the guidance they can offer about business logic, UI flow/layout, etc.  Make sure that your users know that they can approach you with any questions or concerns... they are not a hindrance to your job, they are the reason it exists!

    This is not to say that you should get into deep discussions with a “clueless user who will never get it anyway”... but we should try our best within time constraints to think of metaphors that are easily understandable to someone who cares enough to think about it.  In meetings we shouldn't be afraid to use that white board, draw pictures!  You would be amazed how quickly users can understand relational constraints when you draw it out of them.  Just saying to a group of users “We did X because <insert technical jargon here>” makes them feel like you're hiding behind technical terms which breeds anxiety and distrust.  I have found that the more understandable you can make the technology and programming process, the more the users will be willing to shape their process to match what technology does well... it's a win-win scenario at that point.

    I'll wrap this post up by pointing out that with all the buzz about off-shoring and the general lack of demand in the IT market one of the biggest differentiators we have as programmers is people skills.

  • A few annoyances

    On the lighter side of things, I felt like sharing some of my annoyances.

    1. Programs that have a non-critical event (ie not a catastrophic failure) that grabs focus when said program isn't the current active window.  *looks menacingly at his toolbar*  If my pc isn't about to melt down, then you stay out of my workspace unless I deliberately summon you.  (or at least have an option to control said behavior)

    2. Webpages that set focus to the first editable control.  Pages don't load immediately every time, often some graphic is holding up the process, but I'm already off to the races typing.  Then in the middle of my typing POOF!  My cursor jumps up the form.  I have to delete out whatever I was typing from the first control, and go back down to where I was to continue.

    3. Those ads that roll right across the text you're reading on the web.  (Yeah, there are ways to block them, but man, what sadist thought up these types of ads).

    4. #3, with sound (ever have your speakers up fairly loud from a recent gaming session and have an ad with sound scare the living s--- out of you?)

    5. Javascript, because it has the absolute worst error messages I have ever seen.

    6. People that think that because I'm a programmer I can fix their pc hardware.

  • Custom Controls

    Do you people out there in web-land find yourself making alot of custom controls?

    The place I work in is predominately old school FoxPro with a desire to start moving towards .NET.  One of the things they've done is create a cubic ton of custom controls (it's been a very steep learning curve getting into their systems for me as a developer... for example there are like 10 different custom combo boxes...).

    The theory, as described to me, is that every control should know how to "wire itself" (big chunk of the applications here are just form data in/out to sql server), and it has been suggested to me that they will want to start off in .NET by subclassing every control...

    Now I've been working in .net for 2+ years and I think I've subclassed a control twice... there just isn't alot I've worked on that I could not accomplish easily within the parameters of existing controls.  Plus I think that by avoiding custom controls it makes the learning curve for those who follow behind me a little less steep (gasp a programmer who actually codes trying to help those that come after.  I know, it's not natural!).

    My gut tells me a few things:

    1. You shouldn't subclass anything unless you find a specific need to subclass it.  Why do a bunch of work for nothing?

    2. Creating a cubic ton of custom controls hinders development b/c you have to remember what control for what situation multiplied several times (especially here).

    3. Knowing how to “wire yourself” doesn't require custom controls at all, you can databind just about anything in .NET by default.

    So yeah, toss me some opinions.  =)

  • One step closer...

    #region shameless plug

    Just registered my business!  I'm pretty excited to be throwing my hat into the small business arena.

    I put a draft of my company site up at http://www.easywebapps.com  I already have a few beta clients and I'm probably going to go “public” with the site with google adwords etc. in a few days.

    My business is based on the belief that the technology is powerful enough and scalable enough that full featured business applications can be provided over the internet to small businesses.  I plan on hosting ASP .NET business applications under a subscription based model.

    I've done alot of work with local govt, schools, and small business who desperately need good applications but just don't have the resources to install, configure, and maintain a database + enterprise level application.  I hope to be able to provide a suite of ASP .NET applications that take the features most needed by these smaller entities, break them down until they're simple to use, and then let them share space on a powerful database/internet server.  My company handles all of the administrative overhead and they just use the app!

    I really think this is the future of small business services.

    #endregion

More Posts Next page »

Our Sponsors