Serge's Technology View

Talk about Technologies, Software Architecture and Management

Archive for the ‘Fun stuff with C#’ Category

ASP.Net/WF : New built-in .Net Charting control

I was always for a “built-in” support of features in modern development environment. Even if it comes in basic form, we, as programmers, should have ability to do “basic” stuff without 3rd party involvement.

There are plenty of 3rd party solutions on the market which would help you include some kind of charting support with your ASP pages and WinForms applications – ChartFX, ComponentArt’s Charting, Dundas Chart - these are just few from many available on the market today.

As it turned out, Microsoft has decided to add out-of-the-box support for Charting as well - <asp:chart runat=”server”/>.
Read about it here - New ASP.NET Charting Control: <asp:chart runat=”server”/> by Scott Guthrie – everything you need to know about the .Net 3.5 framework new addition.

For  additional information also visit Alex Gorev’s blog.

Note 1: Even though caption says it is ASP.Net solution, in the original you would find link to WinForms sample as well.
Note 2: Do not worry about Dundas copyright – “Microsoft acquired Dundas Data Visualization Intellectual Property in April 2007.”

Windows 7 and multi-touch – continued

Some time ago I have wrote about steps Microsoft was making into multi-touch interface support inside Windows application.

If you visited PDC 2008, then you probably already heard that Microsoft had officially presented a new .Net framework/API which would be available as part of Windows 7.

If you have missed PDC 2008 this year, you can watch it online here

Future of C# – v 4.0 at PDC 2008

Late August I have brought up a question about default parameters in Delphi. But it does not stop with just Delphi – C# did not have support for default parameters for years…

Not anymore - default or optional parameters would appear in C# of some near future – .Net 4.0 (this is 70+ minutes you have to listen to):

  1. dynamic language support and Dynamically Typed Objects
  2. concurrent applications, multi-core support, parallel programming
  3. befriend C# with VB#
  4. default and named parameters
  5. Compiler as service, compiler API, code delegate, code text as script
  6. more…

Being the father of Delphi and then C#, he could not resist from sharing/exploring further many ideas which we have seen since Delphi 1.0 – VCL, data access, and many other things.

I have always considered C# being a Delphi 2.0 – which Delphi could become if Anders would have an opportunity to extend it at Borland.

Few thoughts:

#1. very nice simplification to the coding practices. Too powerful perhaps? Well, generics were as such when introduced and now we cannot live without it… PHP/Python anyone? Delphi classes from C# without reflection, interfaces or delegation…

#3. Is interesting statement from Microsoft since they did try hard to decommission VB and have not succeeded. I think Borland/CodeGear has tried the same with Delphi and has not succeed with that either. Evolution of the language is inevitable, it has to follow the trend. And I am glad with Prism announced this is something which would be a thing of the past.

#4. default parameters… Finally… a named parameters? mmm… interesting…

#5 as component developer I would love to see this feature in Delphi for dynamic deployment. As a developer I am looking forward for Delphi scripting capabilities…

PS. It is nice to see an acknowledge of his work at Borland in his PDC2008 introduction

Before joining Microsoft in 1996, Hejlsberg was one of the first employees of Borland International Inc. As principal engineer, he was the original author of Turbo Pascal, a revolutionary integrated development environment, and chief architect of its successor, Delphi.

Populate TreeView from table in ASP.Net

I was asked today to help with code which would populate the TreeView control from database table in ASP.Net page.

Since it is not a first time around and appear to be very common situation with dynamic pages, I thought it may be useful to write about it once and then just refer to this post later.

  1. We have a table with the following structure:
    ID ParentID Name
  2. We also have a stored procedure usp_GetGroupList which would return data from table above.
  3. And on our ASP page we have a TreeView control called myTreeView

Few things we are trying to achieve:

  1. Small code
  2. Minimum of database access

Well, code would not be too complex after all:

private void PopulateTree()
{
    // Populate dataset with data for later use
    DataSet dsList = new DataSet();
    SqlConnection conn = new SqlConnection(myConnectionString);
    conn.Open();
    try
    {
        SqlCommand cmd = new SqlCommand("usp_GetGroupList", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter adapt = new SqlDataAdapter(cmd);
        adapt.Fill(dsList);
    }
    finally
    {
        conn.Close();
    }

    // Clear the tree
    myTreeView.Nodes.Clear();
    PopulateTreeNode(dsList, null, "0");
}

private void PopulateTreeNode(DataSet dsList, TreeNode parent, string parentID)
{
    TreeNodeCollection baseNodes;
    string rowID;
    TreeNode node;

    if (parent == null)
    {
        baseNodes = myTreeView.Nodes;
    }
    else
    {
        baseNodes = parent.ChildNodes;
    }

    foreach (DataRow dsRow in dsList.Tables[0].Select("ParentID = " + parentID))
    {
        node = new TreeNode();
        node.Text = dsRow["Name"].ToString();
        rowID = dsRow["ID"].ToString();
        node.Value = rowID;
        node.SelectAction = TreeNodeSelectAction.Select;

        // Add link back to itself so selected group could be changed
        node.NavigateUrl = "~/default.aspx?id=" + rowID;
        baseNodes.Add(node);

        // Use recusion to populate child nodes
        PopulateTreeNode(dsList, node, rowID);

        // Preselect the node for current group
        if (node.Value == Request.QueryString["id"])
        {
            node.Selected = true;
        }
    }
}

Valid XHTML 1.0 Transitional  Valid CSS!