Archive for February 2009

Microsoft certification

One of our clients at work has it in the agreement with us that we need to be certified. Off I went reading a text book about .net framework. The self paced training kit seems to do the job. It’s sorta like being back in school reading a text book. Most of this stuff you already know but there are a few tidbits that are beneficial that you might not have picket up just by using the framework in the real world.

As my colleague had done before me, I signed up for the Prometric second chance exam ( if you fail you get to take it again without paying more ). I had scheduled my exam on Friday at noon. Because of distractions and work I got somewhat behind. On Thursday I decided that I could use one more day studying. I go to the Prometric web site to reschedule for Saturday, but I couldn’t find my information. I call them on Friday morning to reschedule.

It turns out that they do NOT allow you to reschedule your exam unless you do that at least 24HRS before your exam is supposed to start. Therefor I had to drive into Denver and take the exam, use it or lose it. I passed which makes me MS certified and the client is happy.

C# collection in GridView ASP page

I had the need to display a sortable GridView in an Asp page. I have a collection of objects rather than a table object. What I chose to do was to convert the collection into DataView. Then it’s easy to use the built in .net sorting. The collection updates in real time, therefor a timer was added to update the grid every 15 seconds.

First the asp code

<asp:ScriptManager ID=“ScriptManager1” runat=“server” />
         <div>
            <asp:Timer ID=“Timer1” OnTick=“Timer1_Tick” runat=“server” Interval=“15000”>
            </asp:Timer>
        </div>
     <table>
            <tr>
                <td>
                    <asp:Label ID=“HeaderLabel” runat=“server” Text=“” />
                    <Triggers>
                            <br />
                            <asp:AsyncPostBackTrigger ControlID=“Timer1” EventName=“Tick” />
                    </Triggers>
                    <asp:GridView ID=“gvCarGrid”
                                SkinID=“GridView”
                                  CaptionAlign=“Top”
                                  runat=“server”
                                  Font-Size=“Small”
                                  onrowdatabound=“gvCarGrid_RowDataBound”
                                  AllowSorting=“True”
                                  onsorting=“gvCarGrid_Sorting”
                                  > 
                        <Columns>
                            <asp:BoundField ReadOnly=“true” HeaderText=“Model” DataField=“Model”
                                SortExpression=“Model” />
                            <asp:BoundField ReadOnly=“true” HeaderText=“Year” DataField=“Year”
                                SortExpression=“Year” />
                            </asp:BoundField>
                        </Columns>                                         
                    </asp:GridView>
                </td>
            </tr>
       </table>

Then the C# code

private static DataTable mCarTable = new DataTable();
        //
        private const string COL_MODEL = “Model”;
        private const string COL_YEAR  = “Year”;
        //
        private const string ASCENDING = ” ASC”;
        private const string DESCENDING = ” DESC”;
        //
        private const string SORT_ORDER = “sortOrder”;
        private const string SORT_COLUMN = “sortCol”;
       

        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!Page.IsPostBack)
            {
                // State variables
                ViewState[SORT_ORDER] = ASCENDING;
                ViewState[SORT_COLUMN] = COL_MODEL;
                // Intialize
                this.InitTable();
                // Load the grid
                this.loadGrid();
            }
        }

        // Initialize car table to use with the view
        void InitTable()
        {
            mCarTable = new DataTable();
            mCarTable.Columns.Add(COL_MODEL);
            mCarTable.Columns.Add(COL_YEAR, typeof(int));
        }

        // Initialize DataView from list
        private DataView getDataView( IList<Car> plCars )
        {
            mCarTable.Rows.Clear();

            foreach (Car  myCar in plCars )
            {
                DataRow newRow = mCarTable.NewRow();
                //
                newRow[COL_MODEL] = myCar.Model;
                newRow[COL_YEAR] = myCar.Year;
                //
                mCarTable.Rows.Add(newRow);
            }

            return new DataView(mCarTable);
        }

        void loadGrid()
        {
                IList<Car> list = getCarList();
                //
                this.addSortIndicator();
                //
                DataView carView = this.getDataView(list);
                carView.Sort = ViewState[SORT_COLUMN].ToString() + ViewState[SORT_ORDER].ToString();
                //
                gvCarGrid.DataSource = carView;
                gvCarGrid.DataBind();
        }

        // Call before sorting
        protected void gvCarGrid_Sorting(object sender, GridViewSortEventArgs e)
        {
            // Set the correct direction
            if( ViewState[SORT_COLUMN].ToString() == e.SortExpression &&
            ViewState[SORT_ORDER].ToString() == ASCENDING )
                ViewState[SORT_ORDER] = DESCENDING;
            else
                ViewState[SORT_ORDER] = ASCENDING;

            // Set it
            ViewState[SORT_COLUMN] = e.SortExpression;

            // Load it
            this.loadGrid();
        }

        private void addSortIndicator()
        {
            int iCount = 0;
            // Search for the columm with the sort expression
            foreach (DataControlField field in this.gvCarGrid.Columns )
            {
                // Reset the headers first
                field.HeaderText = mCarTable.Columns[iCount++].ColumnName;

                if (field.SortExpression == ViewState[SORT_COLUMN].ToString())
                {
                    // Add indicator to header column
                    if (ViewState[SORT_ORDER].ToString() == ASCENDING)
                        field.HeaderText += CxUtil.ASCENDING_ARROW;
                    else
                        field.HeaderText += CxUtil.DESCENDING_ARROW;
                }
            }

        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            this.loadGrid();
        }

Boulder tech meetup, Feb 3rd

Another good meetup, however the venue is shrinking. There was no way to get a seat if you were not early on the scene. Going forward there are going to be two meetups each month, one in Denver and one in Boulder so look out for that.

I have to say SDP Engineering has a really impressive product.
It was interesting to hear Brad Felds thoughts on VC money etc. in CO.

Presenters were:
SurveyGizmo Presented by Scott McDaniel
TapTapCards Presented by Tim Hampton
SDP Engineering Presented by Ryan Sullivan
Spyder Lynk Presented by Nicole Skogg & Jane McPherson
Fitwise Training, Inc. Presented by Jennifer Lesea-Ames
Brad Feld talking about Venture Capital in Co.