<albertMutangiri:blog runat="server"/>

<albertMutangiri:blog runat="server"/>

The opinions expressed here are MY OWN and are not necessarily those of my employer, partners, customers, friends, or family. ALL content presented AS-IS, for entertainment purposes only with ABSOLUTLY NO WARRANTY expressed or implied.
Easy Javascript MessageBox with ScriptManager

Easy way to create a MessageBox form server side code, Well all you need todo , is to add ScriptManager on your page, and  take advantage of the ScriptManager by calling ScriptManager.RegisterStartupScript()..

 static void DisplayMessage(Control page, string msg)
    {
        string myScript = String.Format("alert('{0}');", msg);
        ScriptManager.RegisterStartupScript(page, page.GetType(),
          "MyScript", myScript, true);
    }
Simply call DisplayMessage and pass the current control context..

DisplayMessage(this,"Product adjustment cant be more than quantity in stock");


Tech-Ed 2009 here we come!

I'm just so excited, last year I couldn't make it but this time its most definite => all roads lead to Durbs. Just got the news from the Boss , they have already budgeted for this event. Yes

 

 

Posted: May 21 2009, 06:19 AM by lexx_debug | with no comments
Filed under:
Tiny Twitter For your mobile Device

Are you a Twitter fan and facebook Addict, Well sometimes you wanna sync your twitter status with facebook. This morning I found this cool lite Twitter App, that runs on your mobile device and your can configure Twitter to send your status directly to facebook, pretty cool. Get it Here

 

I used to own one of these guys way back then

I remember way back then, I used to own this Nintendo gameboy until we had an issue with my mom because she wasn't quite that happy with the idea, since i had to spend more time with this guy and less on my homework, my favourite old classic games that used to rock on one of these guys => Packman, MK , Streetfighter, Terminator .....


gameboy

This was an absolute blast :)

Stay close to the people you care about

Last week i just got caught up into some unplanned expense but i really liked this small little friend. The nice part of it is that it stays very close to me, always attached to my key holder and i can upload a bunch of pictures of all my friends and family members via bluetooth or USB and it's got this cool slide show that i can customize.


 

Editing Data in Nested ListView Control

I have spend a few hours last night digging into the new ListView Control that ships with .Net 3.5. ListView Controls are very flexible and allows you to define how you want your data to be presented. Every time a developer is faced with a task to present data, there is a couple of controls to choose from including third party controls, but one would prefer the most flexible ( easy to work with) control to present data. In most cases developers are faced with complex scenarios to customize controls so that they fit in their problem space, and they end up going through a hell of customizing and this takes quite a bit of time to render just a simple control.

This time for a change, i have decided to go the ListView way. This control has a bunch of templates and allows you to group data in a master detail format, but one needs to customize it as well like for example to hide and show detail i had to use a custom javascript for that. You might be interested in checking this list as well.

1) EmptyDataTemplate
2) ItemSeparatorTemplate
3) GroupTemplate
4) GroupSeparatorTemplate
5) EditItemTemplate
6) InsertItemTemplate
7) LayoutTemplate
8) ItemTemplate
9) AlternatingItemTemplate
10) SelectedItemTemplate
11) EmptyItemTemplate

I have this data model scenario below:


When my Control gets loaded for the first time i bind my ListView as well as Child ListView.

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            loadZoneConfigurations();
    }

    void loadZoneConfigurations()
    {
        try
        {
            using (var db = DatabaseHelper.GetBomData())
            {
                if (null != db)
                {
                    var zones = db.Zones.Select(z =>                       
                        new
                        {
                            z.zoneID,
                            z.zoneName,
                            z.active,
                            z.datecreated,
                            z.Roles      // A Collection of Roles for a specific Zone                                            
                        }
                );

                if (zones != null)
                {
                    lvZones.DataSource = zones;
                    lvZones.DataBind();                       
                }                   
                }              
            }
        }
        catch (Exception ex)
        {
        }
    }



Child ListView Controls gets bound to z.Roles in the Linq query expression when Parent ListView Control OnItemDataBound Event gets fired, so this function below does it all.

//Accepts A ListViewControl Reference and binds Roles to it based on ZoneID

void loadRolesByZone(ListView _roles)
    {
        try
        {
            using (var db = DatabaseHelper.GetBomData())
            {
                var roles = db.Roles
                    .Join(db.Config_Assessments,
                    r => r.roleID,
                    cf => cf.roleID,
                    (r, cf) => new
                    {
                        r.roleName,
                        r.salary,
                        r.sqm,
                        r.roleID,
                        r.datecreated,
                        r.defaultImage,
                        r.active,
                        r.zoneID,
                        cf.assessed,
                        cf.nonassessed,
                    }).Where(z => z.zoneID == Convert.ToInt32(_roles.Attributes["ZoneID"]));
               
                if (null != roles)
                {
                    var lst_roles = _roles as ListView;
                    lst_roles.DataSource = roles;
                    lst_roles.DataBind();
                }
            }
        }
        catch (Exception ex)
        {
       
        }
    }     
 
We can Easily set EditIndex ( EditMode ) for the Parent ListView,  and rebind our listView so far so good :)

 protected void lvZones_ItemEditing(object sender, ListViewEditEventArgs e)
  {
        lvZones.EditIndex = e.NewEditIndex;
        lvZones.InsertItemPosition = InsertItemPosition.None;
        loadZoneConfigurations();
  }

but to set the Edit Index for the Child ListView we need to Rebind that Child ListView and show data in Controls like Texboxes and CheckBox based on our datamodel , that's when the trick comes.

This routine below will throw an Exception Sad

protected void lvRoles_ItemEditing(object sender, ListViewEditEventArgs e)
  {
        var innerListView = ((ListView)sender) as ListView;
        innerListView .InsertItemPosition = InsertItemPosition.None;
       loadRolesByZone(innerListView );
  } 

Since after the call to DataBind(), the item's DataItem is set to null. This means that when calling InnerView's DataBind() on the handler, the ListView's container no longer has a valid DataItem, thus the expressions can't be evaluated at this point in time ( <%# Eval("salary","{0:C}")%> ) == NULL.

One can overcome this by using Reflection to remove the framework's handler before calling DataBind() like below :

protected void lvRoles_ItemEdit(object sender, ListViewEditEventArgs e)
    {
        var innerListView = ((ListView)sender) as ListView;
      
        var pInfo = innerListView.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance);
        var fInfo = typeof(Control).GetField("EventDataBinding", BindingFlags.NonPublic | BindingFlags.Static);

        var handlerList = (EventHandlerList)pInfo.GetValue(innerListView, null);
        var key = fInfo.GetValue(innerListView);

        var handler = handlerList[key];
        handlerList.RemoveHandler(key, handler);
       
        innerListView.EditIndex = e.NewEditIndex;
        loadRolesByZone(innerListView);     
      
    }

We have our Ferrari  at last. Happy Days :)

Posted: Sep 03 2008, 10:54 PM by lexx_debug | with 25 comment(s) |
Filed under: ,
powershell => my blog

Well! this is cool, sometimes i feel like i need a change the way i do stuff, everytime i visit my blog i have to go through a usual task => Start => Programs => Firefox => then my blog.

Well today i'm going to try a different route => Run => Powershell => my blog

I have noted my blog does support rss as well as atom, cool! so why not Linq to my blog.

Bring it on !, lets run powershell.


Ok, now to use Linq, we need to import the required Assembly
[Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq"), as well as create a proxy instance and setting it to use  default credentials configurations, since i'm running behind a proxy. I have removed my proxy address so just plug yours.

 

 so far so good, now lets download our rss feed and parse it using XElement from System.Xml.Linq.XElement

 

 Lastly we can pick titles for all my blog posts by iterating the descendants of my rss feed, with an Element named "Title" like below : PS C:\> $my_blog_rss.Descendants("title") | forEach { $_.value }

 

You can even go further and fetch the published dates

PS C:\> $my_blog_rss.Descendants("pubDate") | forEach { $_.value }

 

 

Design Team for C# 4 - with Anders Hejlsberg

I downloaded this video and all i can say is these guys really rock! There is so much being added to C# language.

http://channel9.msdn.com/posts/Charles/C-40-Meet-the-Design-Team/

Linq Pad

It's been two months now since i started learning Linq and I found this cool tool so exiting for those still learning Linq. Linq makes life easy for developers. Most applications that i develop manipulate and make use of data stored somewhere, XML, Databases like MS SQL or it might be in- memory objects.

It's always not been  easy to work with data accross different datasources and i think Linq makes it quite easy when it comes to manipulating data from diffrent datasources and since I love working my  objects this makes it so cool all i need to know is my LINQ then i can LINQ to XML, in memory objects, SQL without the complexities of going through the XML DOM or other complex stuff.

I gave it a thought in my last project and it was really awesome. With these few lines of code, i managed to pull Xml values with LINQ without going through the hasles of XML DOM.

public static string getGlobalUniqueIds(this XBridgeAbstruction me, string description)
       {
           string _Id="";          
           IEnumerable<XElement> procedures = me.getProcedures();
           var guid = from _guid in procedures.Descendants("guid")
                      where ((System.Xml.Linq.XElement)_guid.NextNode).Value == description
                      select (string)_guid;
           foreach (string gu_id in guid){
               _Id = gu_id;             
           }
           return _Id;
       }

The first days when i heard about LINQ in technical blogs, I was so resistant to move to linq and thanks to my friend who kept on pushing as well as some developer sessions at Microsoft. This is sunch an awesome technology !

I just found this tool online and it's for free, you definitely don't need to pay for it. It comes with a banch of linq sample source code  as well.

 linq Pad

 

 

 

 

 

 

 

 

 

 

 

 

Download  here 

Posted: Jun 30 2008, 05:49 AM by lexx_debug | with 1 comment(s)
Filed under:
Lets talk Silverlight 2 with Brad Abrams

I hope i will make it in time, since i have to drive from RandBurg to Microsoft Bryanston, very close but traffic is hectic. If i can't make it for today, i will be attending the MIX conference, He will be presenting as well i guess.

This is quite an awesome topic, i'm really quite fascinated by the ability to use other languages other than javascript for example Script # ,  with Silverlight.

http://sadeveloper.net/forums/thread/12453.aspx

Cool Stuff

Calling Web Services from Javascript

Asp.net ScriptManager  allows you to call web services asynchronously from javascript. These are some of the cool features that i've liked with Ajax Asp.net. The most important point to note is to make sure that the service to be consumed from javascript is marked with a  [ScriptService] attribute as well as adding a reference call to the .ASMX Path within your ScriptManager and said and done you're ready to go.

 Lets take for example this simple service call from javascript

 In your Asmx.cs  file

    [WebService(Namespace = "http://someservice.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]

    [ScriptService] // Marks this service so that its referenced from javascript
    public class someservice: System.Web.Services.WebService
    {  

        [WebMethod]
        public string helloLovelyWorld(string Message)
        {
            try
            {             
               return Message + "From Lovely World";
             }
             catch(Exception ex)
             {
             
              }
        }
 

To make a call to the service we need to add a scriptManager on our page.
 

<asp:ScriptManager ID="mngrMainScriptManager" runat="server" >
 <Services>
    <asp:ServiceReference
       path="someservice.asmx" />
  </Services>
</asp:ScriptManager>

 This Javascript snipet will make a call to the remote service and returns a string

<script type="text/javascript"> 
 
    function postComment(message)
    {                          
           helloLovelyWorld(message.value,
           SucceededCallback);
    } 
    // This is the callback function that
    // processes the Web Service return value.
    function SucceededCallback(result)
    {
      alert (result);
    }
     
</script>

 

 

Tech-Ed 2008

 All roads lead to Durban this year for yet another exciting moment. Definitely I'm not gonna mis this one.

http://www.tech-ed.co.za/

 

Posted: Apr 02 2008, 11:00 AM by lexx_debug | with no comments
Filed under:
Microsoft announces the CTP release of SQL Server 2005 Drivers for PHP

PHP Developers can now develop applications targeting Microsoft SQL Server with the help of this CTPreview, this is such an awesome idea!

Driver can be downloaded on link below

http://www.microsoft.com/downloads/details.aspx?FamilyID=85f99a70-5df5-4558-991f-8aee8506833c&DisplayLang=en

Microsoft2008.Launch_Wave.Jozi.Attendees.Add(this);

 Can't definitely wait for this one, Two Days to go ! Yes If not registered , please go here

http://www.microsoft.com/southafrica/heroeshappenhere/default.mspx

 

NBA to move to Silverlight Applications

This is definitely exciting, i can now see the light and big thanks to ScottGu and crew, they did an awesome job on Silverlight, Scott deserves the medal, congratts he's now the Corporate Vice President.for NET Developer Platform. job well done.

http://www.nba.com/news/nba_microsoft_071210.html

 

More Posts Next page »