Sonu Kapoor's WebLog

Application Developer, Writer and much more ...

  • Moved Blog

    I have finally managed to move my blog to my own website, which I am still building. The blog however is already fully functional. Please update your bookmark to the new location. I really appreciate all the experience, which I got from Thanks so much.

  • Have you heard of Snippet Compiler?

    Just saw this cool tool called "Snippet Compiler" and thought you would be interested in. Always wanted to compile quickly some code snippets without opening Visual Studio .NET and creating a new project? This small and easy to use tool lets you create such snippets with the benefit of having intellisense, compiler errors, warning, tooltips etc. . Here is a screenshot how it looks like:

    Downlod it here.

    Sonu Kapoor

  • Manage TV viewing via XML

    XMLTV is a set of utilities to manage your TV viewing. They work with TV listings stored in the XMLTV format, which is based on XML. The idea is to separate out the backend (getting the listings) from the frontend (displaying them for the user), and to implement useful operations like picking out your favourite programmes as filters that read and write XML documents.

  • Currency Conversion rates via a Web Service

    Some time ago I found the following Web Service, which provides the currency conversion rates for free. The WebSite also provides some other very nice services. I thought it would be interesting to bookmark that one. What kind of Web Service do you use to do the currency conversion?


  • Add a JavaScript Confirm function when deleting a row from a datagrid

    Lets say your datagrid looks like this:

    <asp:datagrid OnItemDataBound="dg1_OnItemDataBound"...>
      <asp:Button runat="server" Text="Delete" id="btnDelete" CommandName="Delete" CausesValidation="false"></asp:Button>

    And in your ItemDataBound of the datagrid you just need to add this:

    Sub dg1_OnItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
      If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
        CType(e.Item.Cells(0).FindControl("btnDelete"), Button).Attributes.Add("onClick", "return confirm('Are you sure to delete this item?')")
      End If
    End Sub


  • New Design on XMLPitStop

    Just in the case you haven't recognized yet. XMLPitStop has a new design and a cleaner structure. Furthermore we have an admin section which allows us to manage articles and code snippets easily. Feel free to submit your thoughts and ideas to .


  • Cast from type 'DBNull' to type 'String' is not valid.

    I have seen this question many times in the ASP.NET forums and thought that it would be a good idea to blog about.
    When you are working with functions in the HTML of your DataGrid and passing the value (which can be also NULL) from the database to a function, which accepts a string, then you will get such an error.

    Cast from type 'DBNull' to type 'String' is not valid.

    To get this working you will have to pass the value as an object. That means the function must simply accept it as an object instead of a string. Something like this:

    <asp:datagrid id="datagrid".....>
    <asp:TemplateColumn ...>
        <%# DoSomething(Container.DataItem("TheValue")) %>

    And in your Codebehind:

    function public DoSomething(Dim obj as Object)
      If not IsDBNull(obj) then
      ' Do the processing here...
      End If
    end function