Jagadish's profileJagadish Pulakhandam'sPhotosBlogListsMore Tools Help

Blog


    July 31

    Article: Overloading and Overriding in Visual Basic 2005

    Hello,
     
    My article on "Overloading and Overriding in Visual Basic 2005" got published here http://www.aspfree.com/c/a/VB.NET/Overloading-and-Overriding-in-Visual-Basic-NET-2005/
     
    Enjoy...
     
    thanks
    Jag 
    July 24

    Part 2: Programming Crystal Reports with ASP.NET 2.0: working with parameters

    Hello guys,
     
    My latest article focusing on Programming with Crystal Reports with ASP.NET 2.0 (part 2) got published here http://www.aspfree.com/c/a/ASP.NET/Working-with-Parameters-with-Crystal-Reports-and-ASP-NET-2-0/
     
    enjoy and let me know the feedback.
     
    Thanks
    Jag 
    July 11

    TIP: Open popup when clicked on a hyperlink in GridView: Part-2

    Part - 2 of previous Post:
     
     
    --------
    UPDATE: Page refresh upon closing a popup is published here (along with source code) http://jagchat.spaces.live.com/blog/cns!41050F68F010A662!1184.entry 
    --------
     
    The Employee class got coded as following:
     
    Imports Microsoft.VisualBasic
    Imports System.Data
    Imports System.Data.Sqlclient
     
    Public Class Employee
      Private _EmpID As String

      Private _LastName As String
      Private _FirstName As String
      Private _Country As String
     
      Public Property EmpID() As String
        Get
          Return _EmpID
        End Get
        Set(ByVal value As String)
          _EmpID = value
        End Set
      End Property
     
     
      Public Property LastName() As String
        Get
          Return _LastName
        End Get
        Set(ByVal value As String)
          _LastName = value
        End Set
      End Property
     
     
      Public Property FirstName() As String
        Get
          Return _FirstName
        End Get
        Set(ByVal value As String)
          _FirstName = value
        End Set
      End Property
     
      Public Property Country() As String
        Get
          Return _Country
        End Get
        Set(ByVal value As String)
          _Country = value
        End Set
      End Property
     
      Public Function GetEmpList() As dataset
        Dim da As New SqlDataAdapter("SELECT EmployeeID as ID, FirstName + ' ' + LastName as Name FROM Employees", "data source=.\sqlexpress;initial catalog=northwind;user id=sa;password=eXpress2005")
        Dim ds As New DataSet
        da.Fill(ds)
        da.Dispose()
        Return ds
      End Function
     
      Public Function GetEmployee(ByVal EmployeeID As String) As Employee
        Dim da As New SqlDataAdapter("SELECT *  FROM Employees WHERE EmployeeID=" & EmployeeID, "data source=.\sqlexpress;initial catalog=northwind;user id=sa;password=eXpress2005")
        Dim ds As New DataSet
        da.Fill(ds)
        da.Dispose()
        Dim objEmp As New Employee
        With objEmp
          .EmpID = ds.Tables(0).Rows(0)("EmployeeID")
          .LastName = ds.Tables(0).Rows(0)("LastName")
          .FirstName = ds.Tables(0).Rows(0)("FirstName")
          .Country = ds.Tables(0).Rows(0)("Country")
        End With
        Return objEmp
      End Function
    End Class

     
     Finally, the layout of EmpDetails.aspx is designed as follows:
     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="EmpDetails.aspx.vb" Inherits="EmpDetails" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
          <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1">
            <EditItemTemplate>
              LastName:
              <asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>'>
              </asp:TextBox><br />
              Country:
              <asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>'>
              </asp:TextBox><br />
              EmpID:
              <asp:TextBox ID="EmpIDTextBox" runat="server" Text='<%# Bind("EmpID") %>'>
              </asp:TextBox><br />
              FirstName:
              <asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>'>
              </asp:TextBox><br />
              <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                Text="Update">
              </asp:LinkButton>
              <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel">
              </asp:LinkButton>
            </EditItemTemplate>
            <InsertItemTemplate>
              LastName:
              <asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>'>
              </asp:TextBox><br />
              Country:
              <asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>'>
              </asp:TextBox><br />
              EmpID:
              <asp:TextBox ID="EmpIDTextBox" runat="server" Text='<%# Bind("EmpID") %>'>
              </asp:TextBox><br />
              FirstName:
              <asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>'>
              </asp:TextBox><br />
              <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="Insert">
              </asp:LinkButton>
              <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel">
              </asp:LinkButton>
            </InsertItemTemplate>
            <ItemTemplate>
              LastName:
              <asp:Label ID="LastNameLabel" runat="server" Text='<%# Bind("LastName") %>'></asp:Label><br />
              Country:
              <asp:Label ID="CountryLabel" runat="server" Text='<%# Bind("Country") %>'></asp:Label><br />
              EmpID:
              <asp:Label ID="EmpIDLabel" runat="server" Text='<%# Bind("EmpID") %>'></asp:Label><br />
              FirstName:
              <asp:Label ID="FirstNameLabel" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label><br />
            </ItemTemplate>
          </asp:FormView>
       
        </div>
          <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetEmployee"
            TypeName="Employee">
            <SelectParameters>
              <asp:QueryStringParameter Name="EmployeeID" QueryStringField="ID" Type="String" />
            </SelectParameters>
          </asp:ObjectDataSource>
        </form>
    </body>
    </html>
     
    Welcome your comments!
     
    thanks
    Jag

    TIP: Open Popup when clicked on a hyperlink in GridView: Part-1

    This is a small tip which demonstrates the functionality to open a popup (with details page) when the user clicks on any link in a particular column of GridView.  Part-1 contains code for default.aspx and Part-2 (next post) contains the rest of the code.
     
    The beauty of the tip is that there exists no code in code-behind (at UI level) and everything is automatically taken care by ObjectDataSource control.
     
    The page (default.aspx) is designed with the following layout:
     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script language="javascript">
        function openPopup(strOpen)
        {
            open(strOpen, "Info", "status=1, width=300, height=200, top=100, left=300");
        }
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
          <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1">
            <Columns>
              <asp:TemplateField>
                <EditItemTemplate>
                  <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ID") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                  <asp:Label ID="Label1" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
                </ItemTemplate>
              </asp:TemplateField>
              <asp:TemplateField>
                <EditItemTemplate>
                  <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                  &nbsp;<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="<%# Eval(&quot;ID&quot;, &quot;javascript:openPopup('EmpDetails.aspx?ID={0}')&quot;) %>"
                    Text='<%# Bind("Name") %>'></asp:HyperLink>
                </ItemTemplate>
              </asp:TemplateField>
            </Columns>
          </asp:GridView>
       
        </div>
          <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetEmpList"
            TypeName="Employee"></asp:ObjectDataSource>
        </form>
    </body>
    </html>

     
     
    See Part 2 for rest of the code
     
     
    --------
    UPDATE: Page refresh upon closing a popup is published here (along with source code) http://jagchat.spaces.live.com/blog/cns!41050F68F010A662!1184.entry 
    --------
     
    thanks
    Jag 
    July 02

    TIP: Executing Anoynymous Transact-SQL blocks from .NET

    Following is the sample code which executes a Transact-SQL anonymous block dynamically using .NET:
     

    Public Shared Function GetValueFromAnoymousBlock() As String
        Dim s As String
        s = "DECLARE @x int" & ControlChars.NewLine
        s &= "DECLARE @y int" & ControlChars.NewLine
        s &= "DECLARE @z int" & ControlChars.NewLine
        s &= "SET @x = 1" & ControlChars.NewLine
        s &= "SET @y = 2" & ControlChars.NewLine
        s &= "SET @z = @x + @y" & ControlChars.NewLine
        s &= "SELECT @z" & ControlChars.NewLine
     
        Dim cn As New SqlConnection("data source=.\sqlexpress;initial catalog=northwind;user id=sa;password=eXpress2005")
        Dim cmd As New SqlCommand(s, cn)
        Dim da As New SqlDataAdapter(cmd)
        Dim dt As New DataTable
        da.Fill(dt)
        da.Dispose()
        cmd.Dispose()
        If dt.Rows.Count = 0 Then
          Return Nothing
        Else
          Return dt.Rows(0)(0) & ""
        End If
      End Function