Grassroots news from the field & .Net & blogs – level 000

Steve Smith has set up a blog site for soldiers in Iraq.  Now this site won’t be technical at all, but it’s interesting how blogging and specifically, .TEXT, is spreading.  

I’ve been a subscriber to Steve’s army blog since returning from Iraq myself this past April.  I was over there for a little over a year from 2003 to 2004, and I can tell you that no matter where Steve goes, he’ll be able to find a connection to the Internet.  When I arrived in April 2003 (shortly after the initial invasion), there were a few Internet connections available (and usually only available for official business), but as time when on, Internet cafes (full of computers provided for the soldiers) began to pop up, and now most camps have Internet Cafes. 

I wonder if Scott had any idea how popular his .Text app would become.

XPSP2 installed successfully – level 100

I was intentionally not a first adopter on XPSP2 because of the problems some had with installation, but yesterday I attempted to install it on my secondary computer at home.  This isn’t your normal e-mail/MS Word computer.  This computer has so many peripherals attached to it that it’s hard to route the wires.  Two video cards, 3 hard drives, 2 optical.  and it has so much software on it that Program Files is around 20GB by itself.  VS 2002 and 2003, Virtual PC, Adobe stuff, SQL Server, IIS, etc.  While I was away in Iraq for 14 months, I had it set to auto-update so my wife didn’t have to mess with it, so it’s always had the latest patches.  I run Ad-aware and Norton anti virus, and I have to say that I don’t have any spy ware or viruses.  Norton hasn’t caught anything in over 2 years, and I keep it up to date (I don’t open email attachments from strangers).

I was a little uneasy about installing XPSP2 because some people have had problems, but I’ve always had success with MS’s patches.  I shut everything down and turned Norton off and then proceeded to install.  The install went fine, and everything is great.  In the back of my head I wonder if the people who had problems left programs running during the install, left anti-virus on, actually continued to work during the install, or something else besides:  shut down all programs (even extra services you have running – sql server) and let the computer do its thing. 

All in all, it has been as painless as every other MS patch that has been automatically installed.

James Avery’s Going Independent discussion group – level 000

If you haven’t already heard, James Avery has started a Yahoo group dealing with the topic of going independent (quiting your job while continueing to work).  There are already 90 members in the group, so there should be some good content and advice for those inclined to get out from behind a corporate firewall that blogs everything useful on the net.  Heres the group: http://groups.yahoo.com/group/going_independent/

Web Application architecture preference – level 300

I’d like to share my preference in building web applications.  First, I’d like to remember that in ASP 3.0, every page posted information to another page, so every page had to know the URL to the next page.  This created spaghetti-posting, and the web application became very brittle because if a page moved, other pages declaratively linking or posting to it were broken.  Those who implemented large web applications with ASP 3.0 know exactly what I’m talking about.

With ASP.NET the potential for that problem still exists, but some simple design decisions can save  you maintainence time down the road.  Specifically, I’m talking about putting all visible elements and logic in user controls.  I, personally, don’t implement any UI in my .aspx files.  All my .aspx files are there for is to hook up .ascx files.  This makes for no URL binding, and my control flow is all programmatic.  All my screens are different user controls, and a master user control decides which controls to load for a particular screen.

VS has some really great RAD features that make slogging out code very easy, and you will have a working application very quickly, but your maintainability will suffer.  Since I’ve been using my user control method, my apps have been extremely easy to maintain even in the face of changing requirements and design change requests.  Give it a try.

In ASP.NET 2.0, imagine have a .aspx that sets the master page, sets the thems, and then loads a user control.  In this way, your site is VERY flexible.  Your custom screen (user control) could be moved to any page anywhere in the site as well as adapted to different looks by changing the master page and theme.

How to: Add a totals row to your DataGrid before the footer/pager – level 300

In my own dealings, I’ve had to take control of how a DataGrid was rendered. One particular example is adding a Totals row to a grid BEFORE the footer. Here’s a sample:

<asp:DataGrid ID=”dgd” Runat=”server” AutoGenerateColumns=”False”>

<Columns>

<asp:BoundColumn DataField=”Product” HeaderText=”Product”/>

<asp:BoundColumn DataField=”Price” HeaderText=”Price” DataFormatString=”{0:C}”/>

<asp:EditCommandColumn EditText=”Edit” UpdateText=”Update” CancelText=”Cancel” />

</Columns>

</asp:DataGrid>
And the code:
        private void Page_Load(object sender, System.EventArgs e)

{

//creating mock table for data

DataTable dt = new DataTable();

dt.Columns.Add(“Product”);

dt.Columns.Add(“Price”);

dt.Rows.Add(new object[]{“Shoes”, “12.90”});

dt.Rows.Add(new object[]{“Socks”, “3.50”});

dt.Rows.Add(new object[]{“Underpants”, “8.40”});

//binding mock data

dgd.DataSource = dt;

dgd.DataBind();



//adding totals row

DataGridItem row = new DataGridItem(-1, -1, ListItemType.Separator);

TableCell cell = new TableCell();

row.Cells.Add(cell);

cell = new TableCell();

//calculate total

decimal total = 0;

foreach(DataGridItem dgi in dgd.Items)

{

total += decimal.Parse(dgi.Cells[1].Text);

}

cell.Font.Bold = true;

cell.Text = total.ToString(“c”);

row.Cells.Add(cell);

cell = new TableCell();

row.Cells.Add(cell);

dgd.Controls[0].Controls.Add(row);

}
I merely create a new DataGridItem, add what I want, and add it to my grid. I’ve used this concept several times, and I hope it helps out someone else.