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"&gt;
 
<html xmlns="http://www.w3.org/1999/xhtml&quot; >
<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

About Jag

.NET Architect
This entry was posted in ASP.NET and tagged , . Bookmark the permalink.