Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
       
                If Not Page.IsPostBack Then
   If hdnFacilityID.Value <> "" Then
                   LoadLaneAssigmnentDoors(Convert.ToInt64(hdnFacilityID.Value))
    End If
                End If
         

                End If

        Catch ex As Exception
            pnlGlobalMessage.Visible = True
            lblGlobalMessage.Text = "A technical issue has occurred.  A message has been sent to the development team.  Sorry for the inconvenience."
            lblGlobalMessage.Visible = True
            Dim dt As DataTable = Session("user_session")
            Worker.HandleError(ex, "Lane Assignment", Int64.Parse(dt.Rows(0)("user_id")), Request.Browser.Browser.ToString())
        End Try
    End Sub




Public Sub LoadLaneAssigmnentDoors(ByVal facility_ID As Int64)
        If facility_ID <> 0 Then
            hdnfacilitylineid.Value = ""
            Dim dt As New DataTable
            Dim cmd As New SqlCommand
            cmd.CommandType = CommandType.Text
            cmd.CommandText = "select * from facility_lane where facility_ID=" & facility_ID
            dt = DataConnect.GetInstance.GetDt(cmd)
            Dim tcl As New TableCell()
            Dim trl As New TableRow()
            Dim tbmain As New Table()
            Dim trmain As New TableRow()
            Dim trmain1 As New TableRow
            Dim tb As New Table()
            tb.BorderColor = Drawing.Color.SkyBlue
            tb.BorderWidth = 1
            Dim i As Int64 = 0
            Dim j As Int64 = 0
            If dt.Rows.Count <> 0 Then
                For i = 1 To dt.Rows.Count
                    If j = 10 Then
                        j = 5
                    End If
                    j = j + 1
                    Dim tr As New TableRow()
                    Dim tr1 As New TableRow()
                    Dim tr2 As New TableRow()
                    Dim tr3 As New TableRow()
                    Dim tr4 As New TableRow()
                    Dim tr5 As New TableRow()
                    Dim tr6 As New TableRow()
                    Dim tr7 As New TableRow()

                    If hdnfacilitylineid.Value = "" Then
                        hdnfacilitylineid.Value = i & "," & dt.Rows(i - 1)("facility_lane_ID") & "|"
                    Else
                        hdnfacilitylineid.Value = hdnfacilitylineid.Value & i & "," & dt.Rows(i - 1)("facility_lane_ID") & "|"
                    End If


                    Dim lbldoor As New Label()
                    lbldoor.Text = "Door #:"
                    Dim tc As New TableCell()
                    tc.Controls.Add(lbldoor)

                    Dim lbldoor1 As New Label()
                    lbldoor1.ID = "lbldoor1" & i.ToString()
                    lbldoor1.Text = dt.Rows(i - 1)("door_no")
                    lbldoor1.Width = 125
                    Dim tc1 As New TableCell()
                    tc1.Controls.Add(lbldoor1)

                    Dim lbldoorname As New Label()
                    lbldoorname.Text = "Name:"
                    Dim tc15 As New TableCell()
                    tc15.Controls.Add(lbldoorname)

                    Dim lbldoorname1 As New Label()
                    lbldoorname1.ID = "lbldoorname1" & i.ToString()
                    lbldoorname1.Width = 125
                    lbldoorname1.Text = dt.Rows(i - 1)("door_name")
                    Dim tc16 As New TableCell()
                    tc16.Controls.Add(lbldoorname1)

                    Dim lbldirection As New Label()
                    lbldirection.Text = "Direction:"
                    Dim tc2 As New TableCell()
                    tc2.Controls.Add(lbldirection)

                    Dim rdArriving As New RadioButton()
                    rdArriving.Text = "In"
                    rdArriving.ID = "rdArriving" & i.ToString()
                    rdArriving.GroupName = "rd"
                    Dim rdDeparting As New RadioButton()
                    rdDeparting.Text = "Out"
                    rdDeparting.ID = "rdDeparting" & i.ToString()
                    rdDeparting.GroupName = "rd"
                    Dim tc3 As New TableCell()
                    tc3.Controls.Add(rdArriving)
                    tc3.Controls.Add(rdDeparting)

                    Dim lblTrailer As New Label()
                    lblTrailer.Text = "Trailer:"
                    Dim tc4 As New TableCell()
                    tc4.Controls.Add(lblTrailer)

                    Dim txtTrailer As New TextBox()
                    txtTrailer.ID = "txtTrailer" & i.ToString()
                    txtTrailer.Width = 125
                    Dim tc5 As New TableCell()
                    tc5.Controls.Add(txtTrailer)

                    Dim lblCarrier As New Label()
                    lblCarrier.Text = "Carrier:"
                    Dim tc6 As New TableCell()
                    tc6.Controls.Add(lblCarrier)

                    Dim txtCarrier As New TextBox()
                    txtCarrier.ID = "txtCarrier" & i.ToString()
                    txtCarrier.Width = 125
                    Dim tc7 As New TableCell()
                    tc7.Controls.Add(txtCarrier)

                    Dim lblGoingto As New Label()
                    lblGoingto.Text = "Destination:"
                    Dim tc8 As New TableCell()
                    tc8.Controls.Add(lblGoingto)

                    Dim ddGoingto As New DropDownList()
                    ddGoingto.ID = "ddGoingto" & i.ToString()
                    ddGoingto.AutoPostBack = True
                    AddHandler ddGoingto.SelectedIndexChanged, AddressOf OnSelectIndexChanged
                    Dim lst As New ListItem()
                    Dim lst1 As New ListItem()
                    Dim lst2 As New ListItem()
                    lst.Text = "Select"
                    lst.Value = "0"
                    lst1.Text = "Supplier"
                    lst1.Value = "1"
                    lst2.Text = "Customer"
                    lst2.Value = "2"
                    ddGoingto.Items.Add(lst)
                    ddGoingto.Items.Add(lst1)
                    ddGoingto.Items.Add(lst2)
                    ddGoingto.Width = 130
                    Dim tc9 As New TableCell()
                    tc9.Controls.Add(ddGoingto)

                    Dim lblLocationsc As New Label()
                    lblLocationsc.ID = "lblLocationsc" & i.ToString()
                    lblLocationsc.Text = "Company"
                    Dim tc10 As New TableCell()
                    tc10.Controls.Add(lblLocationsc)



                    Dim ddSC As New DropDownList()
                    ddSC.ID = "ddSC" & i.ToString()
                    'ddSC.AutoPostBack = True
                    'AddHandler ddSC.SelectedIndexChanged, AddressOf OnSelectIndexChanged1
                    Dim lstt As New ListItem()
                    lstt.Text = "Select"
                    lstt.Value = "0"
                    ddSC.Items.Add(lstt)
                    ddSC.Width = 130
                    Dim tc11 As New TableCell()
                    tc11.Controls.Add(ddSC)


                    Dim btnsubmit As New Button()
                    btnsubmit.Text = "Submit"
                    btnsubmit.ID = "btnsubmit" & i.ToString()
                    AddHandler btnsubmit.Click, AddressOf btnsubmit_click
                    Dim tc12 As New TableCell()
                    tc12.Controls.Add(btnsubmit)



                    tr.Controls.Add(tc)
                    tr.Controls.Add(tc1)

                    tr7.Controls.Add(tc15)
                    tr7.Controls.Add(tc16)

                    tr1.Controls.Add(tc2)
                    tr1.Controls.Add(tc3)

                    tr2.Controls.Add(tc4)
                    tr2.Controls.Add(tc5)

                    tr3.Controls.Add(tc6)
                    tr3.Controls.Add(tc7)

                    tr4.Controls.Add(tc8)
                    tr4.Controls.Add(tc9)

                    tr5.Controls.Add(tc10)
                    tr5.Controls.Add(tc11)

                    Dim tc14 As New TableCell()
                    tr6.Controls.Add(tc14)
                    tr6.Controls.Add(tc12)

                    tb.Controls.Add(tr)
                    tb.Controls.Add(tr7)
                    tb.Controls.Add(tr1)
                    tb.Controls.Add(tr2)
                    tb.Controls.Add(tr3)
                    tb.Controls.Add(tr4)
                    tb.Controls.Add(tr5)
                    tb.Controls.Add(tr6)

                    Dim tcc As New TableCell()
                    tcc.Controls.Add(tb)
                    If j > 5 And j < 11 Then
                        If j = 11 Or j = 6 Then
                            trmain1 = New TableRow()
                        End If
                        trmain1.Controls.Add(tcc)
                        tbmain.Controls.Add(trmain1)
                    Else
                        trmain.Controls.Add(tcc)
                        tbmain.Controls.Add(trmain)
                    End If
                    tb = New Table()
                    tb.BorderColor = Drawing.Color.SkyBlue
                    tb.BorderWidth = 1
                    tcl.Controls.Add(tbmain)
                    trl.Cells.Add(tcl)
                    tbl.Rows.Add(trl)
                    tbl.EnableViewState = True
                    ViewState("tbl") = True
                Next

            End If
        End If
    End Sub






Private Sub OnSelectIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        Try
            Dim ddl As DropDownList = DirectCast(sender, DropDownList)
            Dim ID As String = ""
            ID = ddl.ID
            Dim cid As String = ""
            cid = ddl.ID.Replace("ddGoingto", "")
            Dim type As Int64 = 0
            type = ddl.SelectedValue

            Dim ddSC As New DropDownList()
            ddSC = CType(pnllane.FindControl("ddSC" & cid), DropDownList)
            If type = "1" Then
                Dim cmd As New SqlCommand
                cmd.CommandType = CommandType.Text
                cmd.CommandText = "select Supplier_id,Supplier_name from Supplier where client_id=" & Convert.ToInt64(Session("laneclientId"))
                Worker.combofill(cmd, ddSC, "Supplier_id", "Supplier_name")
            Else
                Dim cmd As New SqlCommand
                cmd.CommandType = CommandType.Text
                cmd.CommandText = "select customer_id,customer_name from customer where Client_id=" & Convert.ToInt64(Session("laneclientId"))
                Worker.combofill(cmd, ddSC, "customer_id", "customer_name")
            End If
            'End If
        Catch ex As Exception
            pnlGlobalMessage.Visible = True
            lblGlobalMessage.Text = "A technical issue has occurred.  A message has been sent to the development team.  Sorry for the inconvenience."
            lblGlobalMessage.Visible = True
            Dim dt As DataTable = Session("user_session")
            Worker.HandleError(ex, "Lane Assignment", Int64.Parse(dt.Rows(0)("user_id")), Request.Browser.Browser.ToString())
        End Try
    End Sub




Protected Overrides Function SaveViewState() As Object
        Dim newViewState As Object() = New Object(1) {}

        Dim txtValues As New List(Of String)()

        For Each row As TableRow In tbl.Controls
            For Each cell As TableCell In row.Controls
                For Each tb As Table In cell.Controls
                    For Each rw As TableRow In tb.Controls
                        For Each cl As TableCell In rw.Controls
                            For Each tbb As Table In cl.Controls
                                For Each rww As TableRow In tbb.Controls
                                    For Each cll As TableCell In rww.Controls
                                        If cll.Controls.Count <> 0 Then
                                            If TypeOf cll.Controls(0) Is DropDownList Then
                                                txtValues.Add(DirectCast(cll.Controls(0), DropDownList).SelectedIndex.ToString())
                                            End If
                                        End If
                                    Next
                                Next
                            Next
                        Next
                    Next
                Next
            Next
        Next

        newViewState(0) = txtValues.ToArray()
        newViewState(1) = MyBase.SaveViewState()
        Return newViewState
    End Function
    Protected Overrides Sub LoadViewState(ByVal savedState As Object)

        'if we can identify the custom view state as defined in the override for SaveViewState
        If TypeOf savedState Is Object() AndAlso DirectCast(savedState, Object()).Length = 2 AndAlso TypeOf DirectCast(savedState, Object())(0) Is String() Then
            Dim newViewState As Object() = DirectCast(savedState, Object())
            Dim txtValues As String() = DirectCast(newViewState(0), String())
            If txtValues.Length > 0 Then
                're-load tables
                If Session("lanefacilityId") IsNot Nothing Then
                    LoadLaneAssigmnentDoors(Convert.ToInt64(Session("lanefacilityId")))
                    Dim i As Integer = 0
                    For Each row As TableRow In tbl.Controls
                        For Each cell As TableCell In row.Controls
                            For Each tb As Table In cell.Controls
                                For Each rw As TableRow In tb.Controls
                                    For Each cl As TableCell In rw.Controls
                                        For Each tbb As Table In cl.Controls
                                            For Each rww As TableRow In tbb.Controls
                                                For Each cll As TableCell In rww.Controls
                                                    If cll.Controls.Count <> 0 Then
                                                        If TypeOf cll.Controls(0) Is DropDownList AndAlso i < txtValues.Length - 1 Then
                                                            DirectCast(cll.Controls(0), DropDownList).SelectedIndex = Convert.ToInt32(txtValues(System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)))
                                                        End If
                                                    End If
                                                Next
                                            Next
                                        Next
                                    Next
                                Next
                            Next
                        Next
                    Next
                End If

            End If
            'load the ViewState normally
            MyBase.LoadViewState(newViewState(1))
        Else
            MyBase.LoadViewState(savedState)
        End If
    End Sub
<ajaxToolkit:AsyncFileUpload ID="pfepimage" Width="205px" runat="server" UploaderStyle="Modern"
                                                                    ThrobberID="pfeploader" OnClientUploadStarted="uploadStarted1" />
                                                                <asp:Image ID="pfeploader" runat="server" ImageUrl="~/Images/al_loading.gif" Height="15"
                                                                    Width="15" />
                                                                <asp:UpdatePanel ID="UpdImgDisplay" runat="server">
                                                                    <ContentTemplate>
                                                                        <asp:Image runat="server" AlternateText="No Image" ID="imgFirst" Height="50" Width="50" />
                                                                    </ContentTemplate>
                                                                </asp:UpdatePanel>
                                                                <asp:Label runat="server" ID="lblImageError" Text="*" ForeColor="Red" Visible="false"></asp:Label>



  <script type="text/javascript">
            function uploadStarted1() {
            }

        </script>






Private Sub pfepimage_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles pfepimage.UploadedComplete

        Session("imagefile") = sender
        Dim extn As String
        Dim fStrm As Stream
        Dim FileContent As Byte()
        extn = Path.GetExtension(pfepimage.PostedFile.FileName)
        fStrm = pfepimage.PostedFile.InputStream

        Dim FullFileContent As Byte()
        FullFileContent = New Byte(pfepimage.PostedFile.ContentLength - 1) {}
        fStrm.Read(FullFileContent, 0, pfepimage.PostedFile.ContentLength)

        FileContent = createThumbNail(fStrm, 100, 100)
        Session("imageFileName") = pfepimage.PostedFile.FileName.ToString()
        Session("imageContent") = FileContent

        Dim savePath As String = MapPath("~/PFEPlabels/" & System.IO.Path.GetFileName(e.FileName))
        pfepimage.SaveAs(savePath)
        ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "image", "top.$get(""" + imgFirst.ClientID & """).src = 'PFEPlabels/" & System.IO.Path.GetFileName(e.FileName) & "';", True)
        ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "size", "top.$get(""" + lblImageError.ClientID & """).innerHTML = 'Uploaded';", True)

        ModalUnitLoadDataSheet.Show()

    End Sub
    Private Function createThumbNail(ByVal ImageStream As Stream, ByVal tWidth As Double, ByVal tHeight As Double) As Byte()
        Dim g As System.Drawing.Image = System.Drawing.Image.FromStream(ImageStream)
        Dim thumbSize As System.Drawing.Size = New System.Drawing.Size
        thumbSize = NewThumbSize(g.Width, g.Height, tWidth, tHeight)
        Dim imgOutput As New System.Drawing.Bitmap(g, thumbSize.Width, thumbSize.Height)
        Dim imgStream As MemoryStream = New MemoryStream
        Dim thisFormat As System.Drawing.Imaging.ImageFormat = g.RawFormat
        imgOutput.Save(imgStream, thisFormat)
        Dim imgBinLength As Integer = CType(imgStream.Length, Integer)
        Dim imgBin() As Byte = New Byte((imgBinLength) - 1) {}
        imgStream.Position = 0
        Dim n As Integer = imgStream.Read(imgBin, 0, imgBinLength)
        g.Dispose()
        imgOutput.Dispose()
        Return imgBin
    End Function

    Private Function NewThumbSize(ByVal currentwidth As Double, ByVal currentheight As Double, ByVal newWidth As Double, ByVal newHeight As Double) As System.Drawing.Size
        Dim tempMultiplier As Double

        If currentheight > currentwidth Then
            tempMultiplier = newHeight / currentheight
        Else
            tempMultiplier = newWidth / currentwidth
        End If
        Dim NewSize As New System.Drawing.Size(Convert.ToInt16(currentwidth * tempMultiplier), Convert.ToInt16(currentheight * tempMultiplier))
        Return NewSize

    End Function

    Private Sub savePFEPLabel(ByVal pfepId As Integer)
        Dim cmd As New SqlCommand
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "sp_PFEP_Cont_Label_Img_addUpdate"

        If hdnPFEPLabel.Value = "" Then
            cmd.Parameters.Add("@Label_Img_ID", SqlDbType.BigInt, 0).Value = -1
        Else
            cmd.Parameters.Add("@Label_Img_ID", SqlDbType.BigInt, 0).Value = Convert.ToInt64(hdnPFEPLabel.Value)
        End If
        cmd.Parameters("@Label_Img_ID").Direction = ParameterDirection.InputOutput
        cmd.Parameters.Add("@PFEP_ID", SqlDbType.Int, 0).Value = pfepId
        cmd.Parameters.Add("@Container_ID", SqlDbType.BigInt, 0).Value = Convert.ToInt64(comboContainer1.SelectedValue.ToString())
        cmd.Parameters.Add("@FileName", SqlDbType.VarChar, 100).Value = Session("imageFileName")
        cmd.Parameters.Add("@FileContent", SqlDbType.Image).Value = Session("imagecontent")
        _dtLoggedInUser = Session("user_session")
        Dim dt As DataTable
        dt = Session("user_session")
        cmd.Parameters.Add("@Created_ID", SqlDbType.BigInt, 0).Value = Convert.ToInt64(dt.Rows(0)("user_id").ToString())
        cmd.Parameters.Add("Update_ID", SqlDbType.BigInt, 0).Value = Convert.ToInt64(dt.Rows(0)("user_id").ToString())

        DataConnect.GetInstance.ExecuteNonQuery(cmd)
        hdnPFEPLabel.Value = cmd.Parameters("@Label_Img_ID").Value.ToString()

        If File.Exists(Server.MapPath("~/PFEPlabels/") + "img.jpg") Then
            File.Delete(Server.MapPath("~/PFEPlabels/") + "img.jpg")
        End If
    End Sub
    Private Sub showImage(ByVal pfepId As Integer)
        Dim dt As New DataTable
        dt = DataConnect.GetInstance.GetDt("SELECT * FROM PFEP_Cont_Label_Img WHERE PFEP_ID=" & pfepId)
        If dt.Rows.Count > 0 Then
            Session("imageFileName") = dt.Rows(0)("FileName")
            Session("imageContent") = DirectCast(dt.Rows(0)("FileContent"), [Byte]())

        End If
        imgFirst.ImageUrl = "imgHandle.ashx?id=" & pfepId

    End Sub





Imports System.Web
Imports System.Web.Services
Imports System.Data.SqlClient

Public Class imgHandle
    Implements System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Try
            Dim pfep_id As String = ""
            pfep_id = context.Request.QueryString("id")
            If pfep_id <> "" Then
                Dim dt As DataTable
                dt = DataConnect.GetInstance.GetDt("SELECT * FROM PFEP_Cont_Label_Img WHERE PFEP_ID=" & pfep_id)
                context.Response.Clear()
                If dt.Rows.Count > 0 Then
                    context.Response.BinaryWrite(DirectCast(dt.Rows(0)("FileContent"), [Byte]()))
                Else
                    context.Response.Write("sss")
                End If
                context.Response.End()
                context.Response.Flush()
            End If
        Catch ex As Exception
            context.Response.End()
        End Try
    End Sub

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class

DataConnect.vb

Imports System.Configuration.ConfigurationManager
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient


Public Class DataConnect
    Private Shared _DataConnect As DataConnect
    Private _ConnectString As String

    Public Shared ReadOnly Property GetInstance As DataConnect
        Get
            If _DataConnect Is Nothing Then
                _DataConnect = New DataConnect
                _DataConnect.IntialiseMe()
            End If
            Return _DataConnect
        End Get

    End Property

    Private Sub IntialiseMe()
        BuildConnectionString()
    End Sub

    Private Sub BuildConnectionString()
        _ConnectString = Convert.ToString(ConfigurationManager.ConnectionStrings("SurgereConnection"))
        Using cn = New SqlConnection(_ConnectString)
            cn.Open()
            cn.Close()
        End Using
    End Sub
    Public Function GetDt(ByVal SQL As String) As DataTable
        Using cn = New SqlConnection(_ConnectString)
            Dim da As SqlDataAdapter = New SqlDataAdapter(SQL, cn)
            Dim dt As DataTable = New DataTable
            da.Fill(dt)
            Return dt
        End Using
    End Function
    'Public Function GetDTLang(ByVal SQL As String, ByVal lang As String) As DataTable
    '    Dim lt As New LanguageTranslator
    '    Using cn = New SqlConnection(_ConnectString)
    '        Dim da As SqlDataAdapter = New SqlDataAdapter(SQL, cn)
    '        Dim dt As DataTable = New DataTable
    '        da.Fill(dt)
    '        Dim clmns As Integer = dt.Columns.Count
    '        Dim rows As Integer = dt.Rows.Count
    '        For Each dr As DataRow In dt.Rows
    '            For i As Integer = 0 To clmns - 1
    '                If dr(i).ToString() <> "" Or dr(i).ToString() <> System.DBNull.Value.ToString() Then
    '                    dr(i) = lt.Translate(dr(i).ToString(), lang)
    '                Else
    '                    dr(i) = DBNull.Value
    '                End If
    '            Next
    '        Next
    '        dt.AcceptChanges()
    '        Return dt
    '    End Using
    'End Function
    Public Function GetData(ByVal cm As SqlCommand) As DataTable
        Using cn = New SqlConnection(_ConnectString)
            cn.Open()
            cm.Connection = cn
            Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
            Dim dt As DataTable = New DataTable
            da.Fill(dt)
            Return dt
        End Using
    End Function
    Public Function GetDt(ByVal cmm As SqlCommand) As DataTable
        Using cn = New SqlConnection(_ConnectString)
            cn.Open()
            cmm.Connection = cn
            Dim da As SqlDataAdapter = New SqlDataAdapter(cmm)
            Dim dt As DataTable = New DataTable
            da.Fill(dt)
            Return dt
        End Using
    End Function
    'Public Function GetDTLang(ByVal cmm As SqlCommand, ByVal lang As String) As DataTable
    '    Dim lt As New LanguageTranslator
    '    Using cn = New SqlConnection(_ConnectString)
    '        cn.Open()
    '        cmm.Connection = cn
    '        Dim da As SqlDataAdapter = New SqlDataAdapter(cmm)
    '        Dim dt As DataTable = New DataTable
    '        da.Fill(dt)
    '        Dim clmns As Integer = dt.Columns.Count
    '        Dim rows As Integer = dt.Rows.Count
    '        For Each dr As DataRow In dt.Rows
    '            For i As Integer = 0 To clmns - 1
    '                If dr(i).ToString() <> "" Or dr(i).ToString() <> System.DBNull.Value.ToString() Then
    '                    dr(i) = lt.Translate(dr(i).ToString(), lang)
    '                Else
    '                    dr(i) = DBNull.Value
    '                End If
    '            Next
    '        Next
    '        dt.AcceptChanges()
    '        Return dt
    '    End Using
    'End Function

    Public Function ExecuteScalar(ByVal cmm As SqlCommand) As Object
        Dim result As Object
        Using cn = New SqlConnection(_ConnectString)
            cn.Open()
            cmm.Connection = cn
            result = cmm.ExecuteScalar()
            cn.Close()
            Return result
        End Using
    End Function
    Public Function ExecuteNonQuery(ByVal cmm As SqlCommand) As Object

        Dim result As Object

        Using cn = New SqlConnection(_ConnectString)
            cn.Open()
            cmm.Connection = cn
            result = cmm.ExecuteNonQuery()
            cn.Close()
            Return result
        End Using
        Return -1
    End Function

 
End Class
 Dim txt As New TextBox()
                txt.ID = "txt" & i.ToString()
                txt.MaxLength = 6
                txt.Attributes.Add("onblur", "validate(this);")
                Dim ftext As New AjaxControlToolkit.FilteredTextBoxExtender()
                ftext.TargetControlID = txt.ClientID
                ftext.FilterType = AjaxControlToolkit.FilterTypes.Numbers Or AjaxControlToolkit.FilterTypes.Custom
                ftext.ValidChars = "."
                Dim req As New RequiredFieldValidator()
                req.ID = "req" & i.ToString()
                req.ControlToValidate = txt.ClientID
                req.ErrorMessage = "*"
                req.ForeColor = Drawing.Color.Red
                req.Enabled = True
                req.Visible = True
                req.EnableViewState = True
                req.Display = ValidatorDisplay.Dynamic
                req.ValidationGroup = "rej"
 Dim lanedoors As New LaneDoors
                    lanedoors = LoadControl("~/LaneDoors.ascx")
                    lanedoors.ID = "lanedoors" & i.ToString()
                    lanedoors.Facility_Lane_ID = Convert.ToInt64(dt.Rows(i - 1)("facility_lane_ID"))
                    lanedoors.DoorNo = dt.Rows(i - 1)("door_no")
                    lanedoors.DoorName = dt.Rows(i - 1)("door_name")
                    Dim tc As New TableCell()
                    tc.Controls.Add(lanedoors)
Public Property DoorNo() As String
        Get
            Return m_DoorNo
        End Get
        Set(ByVal value As String)
            m_DoorNo = value
        End Set
    End Property
    Private m_DoorNo As String = ""
    Public Property DoorName() As String
        Get
            Return m_DoorName
        End Get
        Set(ByVal value As String)
            m_DoorName = value
        End Set
    End Property
    Private m_DoorName As String = ""
    Public Property Facility_Lane_ID() As Int64
        Get
            Return m_Facility_Lane_ID
        End Get
        Set(ByVal value As Int64)
            m_Facility_Lane_ID = value
        End Set
    End Property
    Private m_Facility_Lane_ID As Int64 = -1
    Public Property ySelected() As String
        Get
            Return ddSC.SelectedValue
        End Get
        Set(ByVal value As String)
            ddSC.SelectedValue = value
        End Set
    End Property
    Public Property dddSC() As DropDownList
        Get
            Return m_ddSC
        End Get
        Protected Set(ByVal value As DropDownList)
            m_ddSC = value
        End Set
    End Property
    Private m_ddSC As DropDownList

Public Property DoorNo() As String
        Get
            Return m_DoorNo
        End Get
        Set(ByVal value As String)
            m_DoorNo = value
        End Set
    End Property
    Private m_DoorNo As String = ""
    Public Property DoorName() As String
        Get
            Return m_DoorName
        End Get
        Set(ByVal value As String)
            m_DoorName = value
        End Set
    End Property
    Private m_DoorName As String = ""
    Public Property Facility_Lane_ID() As Int64
        Get
            Return m_Facility_Lane_ID
        End Get
        Set(ByVal value As Int64)
            m_Facility_Lane_ID = value
        End Set
    End Property
    Private m_Facility_Lane_ID As Int64 = -1
    Public Property ySelected() As String
        Get
            Return ddSC.SelectedValue
        End Get
        Set(ByVal value As String)
            ddSC.SelectedValue = value
        End Set
    End Property
    Public Property dddSC() As DropDownList
        Get
            Return m_ddSC
        End Get
        Protected Set(ByVal value As DropDownList)
            m_ddSC = value
        End Set
    End Property
    Private m_ddSC As DropDownList

 protected void dglistinner_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem | e.Item.ItemType == ListItemType.Item)
            {
              ImageButton lnk = new ImageButton();
                lnk = (ImageButton)e.Item.FindControl("img");
               lnk.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this Data?');");
            }
        }
        catch (Exception ex)
        {
        }
    }
 protected void dglistinner_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem | e.Item.ItemType == ListItemType.Item)
            {
              ImageButton lnk = new ImageButton();
                lnk = (ImageButton)e.Item.FindControl("img");
               lnk.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this Data?');");
            }
        }
        catch (Exception ex)
        {
        }
    }
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Show Inline validation Messages</title>
<link href="css/template.css" rel="stylesheet" type="text/css" />
<link href="css/validationEngine.jquery.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.6.min.js" type="text/javascript"></script>
<script src="js/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#form1").validationEngine();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<table align="center">
<tr>
<td colspan="2">
<div style="border: 1px solid #CCCCCC; padding: 10px;">
<table cellpadding="0" cellspacing="30" style=" background-color:White">
<tr>
<td>First Name:</td>
<td><asp:TextBox ID="txtfname"  runat="server" CssClass="validate[required]"/></td>
</tr>
<tr>
<td>Last Name:</td>
<td><asp:TextBox ID="txtlname"  runat="server" CssClass="validate[required]"/></td>
</tr>
<tr >
<td>Email:</td>
<td><asp:TextBox ID="txtemail" runat="server"  CssClass="validate[required,custom[email]" />
</td>
</tr>
<tr >
<td>Url:</td>
<td><asp:TextBox ID="txtUrl" runat="server" CssClass="validate[required,custom[url]] text-input" />
</td>
</tr>
<tr>
<td valign="top">Address:</td>
<td>
<asp:TextBox ID="txtaddress" runat="server" TextMode="MultiLine" Rows="8" Columns="26"/></td>
</tr>
<tr>
<td>State:</td>
<td>
<asp:DropDownList ID="ddlState" runat="server" CssClass="validate[required] radio">
<asp:ListItem value="">Choose State</asp:ListItem>
<asp:ListItem Value="AL">Alabama</asp:ListItem>
<asp:ListItem value="AK">Alaska</asp:ListItem>
<asp:ListItem  value="AL">Alabama </asp:ListItem>
<asp:ListItem  value="AK">Alaska</asp:ListItem>
<asp:ListItem  value="AZ">Arizona</asp:ListItem>
<asp:ListItem  value="AR">Arkansas</asp:ListItem>
<asp:ListItem  value="CA">California</asp:ListItem>
<asp:ListItem  value="CO">Colorado</asp:ListItem>
<asp:ListItem  value="CT">Connecticut</asp:ListItem>
<asp:ListItem  value="DE">Delaware</asp:ListItem>
<asp:ListItem  value="FL">Florida</asp:ListItem>
<asp:ListItem  value="GA">Georgia</asp:ListItem>
<asp:ListItem  value="HI">Hawaii</asp:ListItem>
<asp:ListItem  value="ID">Idaho</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>Zip:</td>
<td>
<asp:TextBox ID="txtZip" runat="server" CssClass="validate[required,custom[integer]] text-input"/>
</td>
</tr>
<tr>
<td> I Agree Conditions</td>
<td>
<input class="validate[required] checkbox" type="checkbox" id="agree" name="agree"/>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblResult" runat="server" Font-Bold="true"/>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>





using System;
using System.Drawing;

protected void btnSubmit_Click(object sender, EventArgs e)
{
lblResult.Visible = true;
lblResult.Text = "Validated all the controls";
lblResult.ForeColor = Color.Green;
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Show Inline validation Messages</title>
<link href="css/template.css" rel="stylesheet" type="text/css" />
<link href="css/validationEngine.jquery.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.6.min.js" type="text/javascript"></script>
<script src="js/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#form1").validationEngine();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<table align="center">
<tr>
<td colspan="2">
<div style="border: 1px solid #CCCCCC; padding: 10px;">
<table cellpadding="0" cellspacing="30" style=" background-color:White">
<tr>
<td>First Name:</td>
<td><asp:TextBox ID="txtfname"  runat="server" CssClass="validate[required]"/></td>
</tr>
<tr>
<td>Last Name:</td>
<td><asp:TextBox ID="txtlname"  runat="server" CssClass="validate[required]"/></td>
</tr>
<tr >
<td>Email:</td>
<td><asp:TextBox ID="txtemail" runat="server"  CssClass="validate[required,custom[email]" />
</td>
</tr>
<tr >
<td>Url:</td>
<td><asp:TextBox ID="txtUrl" runat="server" CssClass="validate[required,custom[url]] text-input" />
</td>
</tr>
<tr>
<td valign="top">Address:</td>
<td>
<asp:TextBox ID="txtaddress" runat="server" TextMode="MultiLine" Rows="8" Columns="26"/></td>
</tr>
<tr>
<td>State:</td>
<td>
<asp:DropDownList ID="ddlState" runat="server" CssClass="validate[required] radio">
<asp:ListItem value="">Choose State</asp:ListItem>
<asp:ListItem Value="AL">Alabama</asp:ListItem>
<asp:ListItem value="AK">Alaska</asp:ListItem>
<asp:ListItem  value="AL">Alabama </asp:ListItem>
<asp:ListItem  value="AK">Alaska</asp:ListItem>
<asp:ListItem  value="AZ">Arizona</asp:ListItem>
<asp:ListItem  value="AR">Arkansas</asp:ListItem>
<asp:ListItem  value="CA">California</asp:ListItem>
<asp:ListItem  value="CO">Colorado</asp:ListItem>
<asp:ListItem  value="CT">Connecticut</asp:ListItem>
<asp:ListItem  value="DE">Delaware</asp:ListItem>
<asp:ListItem  value="FL">Florida</asp:ListItem>
<asp:ListItem  value="GA">Georgia</asp:ListItem>
<asp:ListItem  value="HI">Hawaii</asp:ListItem>
<asp:ListItem  value="ID">Idaho</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>Zip:</td>
<td>
<asp:TextBox ID="txtZip" runat="server" CssClass="validate[required,custom[integer]] text-input"/>
</td>
</tr>
<tr>
<td> I Agree Conditions</td>
<td>
<input class="validate[required] checkbox" type="checkbox" id="agree" name="agree"/>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblResult" runat="server" Font-Bold="true"/>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>





using System;
using System.Drawing;

protected void btnSubmit_Click(object sender, EventArgs e)
{
lblResult.Visible = true;
lblResult.Text = "Validated all the controls";
lblResult.ForeColor = Color.Green;
}
<%@ Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" tagPrefix="ajax" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptmanager1" runat="server"></asp:ScriptManager>
<div>
<table>
<tr>
<td>
Select Country:
</td>
<td>
<asp:DropDownList ID="ddlcountry" runat="server"></asp:DropDownList>
<ajax:CascadingDropDown ID="ccdCountry" runat="server" Category="Country"TargetControlID="ddlcountry" PromptText="Select Country" LoadingText="Loading Countries.."ServiceMethod="BindCountryDetails" ServicePath="CascadingDropdown.asmx">
</ajax:CascadingDropDown>
</td>
</tr>
<tr>
<td>
Select State:
</td>
<td>
<asp:DropDownList ID="ddlState" runat="server"></asp:DropDownList>
<ajax:CascadingDropDown ID="ccdState" runat="server" Category="State" ParentControlID="ddlcountry"TargetControlID="ddlState" PromptText="Select State" LoadingText="Loading States.."ServiceMethod="BindStateDetails" ServicePath="CascadingDropdown.asmx">
</ajax:CascadingDropDown>
</td>
</tr>
<tr>
<td>
Select Region:
</td>
<td>
<asp:DropDownList ID="ddlRegion" runat="server"></asp:DropDownList>
<ajax:CascadingDropDown ID="ccdRegion" runat="server" Category="Region" ParentControlID="ddlState"TargetControlID="ddlRegion" PromptText="Select Region" LoadingText="Loading Regions.."ServiceMethod="BindRegionDetails" ServicePath="CascadingDropdown.asmx">
</ajax:CascadingDropDown>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>


CascadingDropdown.asmx

using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using AjaxControlToolkit;


/// <summary>
/// Summary description for CascadingDropdown
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class CascadingDropdown : System.Web.Services.WebService
{
//Database connection string
private static string strconnection = ConfigurationManager.AppSettings["ConnectionString"].ToString();
//database connection
SqlConnection concountry = new SqlConnection(strconnection);
public CascadingDropdown () {

//Uncomment the following line if using designed components
//InitializeComponent();
}
/// <summary>
/// WebMethod to Populate COuntry Dropdown
/// </summary>
[WebMethod]
public CascadingDropDownNameValue[] BindCountryDetails(string knownCategoryValues,string category)
{
concountry.Open();
SqlCommand cmdcountry = new SqlCommand("select * from CountryTable", concountry);
cmdcountry.ExecuteNonQuery();
SqlDataAdapter dacountry = new SqlDataAdapter(cmdcountry);
DataSet dscountry = new DataSet();
dacountry.Fill(dscountry);
concountry.Close();
//create list and add items in it by looping through dataset table
List<CascadingDropDownNameValue> countrydetails = new List<CascadingDropDownNameValue>();
foreach(DataRow dtrow in dscountry.Tables[0].Rows)
{
string CountryID = dtrow["CountryID"].ToString();
string CountryName = dtrow["CountryName"].ToString();
countrydetails.Add(new CascadingDropDownNameValue(CountryName, CountryID));
}
return countrydetails.ToArray();
}
/// <summary>
/// WebMethod to Populate State Dropdown
/// </summary>
[WebMethod]
public CascadingDropDownNameValue[] BindStateDetails(string knownCategoryValues,string category)
{
int countryID;
//This method will return a StringDictionary containing the name/value pairs of the currently selected values
StringDictionary countrydetails =AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
countryID = Convert.ToInt32(countrydetails["Country"]);
concountry.Open();
SqlCommand cmdstate = new SqlCommand("select * from StateTable where CountryID=@CountryID", concountry);
cmdstate.Parameters.AddWithValue("@CountryID", countryID);
cmdstate.ExecuteNonQuery();
SqlDataAdapter dastate = new SqlDataAdapter(cmdstate);
DataSet dsstate = new DataSet();
dastate.Fill(dsstate);
concountry.Close();
//create list and add items in it by looping through dataset table
List<CascadingDropDownNameValue> statedetails = new List<CascadingDropDownNameValue>();
foreach (DataRow dtrow in dsstate.Tables[0].Rows)
{
string StateID = dtrow["StateID"].ToString();
string StateName = dtrow["StateName"].ToString();
statedetails.Add(new CascadingDropDownNameValue(StateName, StateID));
}
return statedetails.ToArray();
}
/// <summary>
/// WebMethod to Populate Region Dropdown
/// </summary>
[WebMethod]
public CascadingDropDownNameValue[] BindRegionDetails(string knownCategoryValues, string category)
{
int stateID;
//This method will return a StringDictionary containing the name/value pairs of the currently selected values
StringDictionary statedetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
stateID = Convert.ToInt32(statedetails["State"]);
concountry.Open();
SqlCommand cmdregion = new SqlCommand("select * from RegionTable where StateID=@StateID", concountry);
cmdregion.Parameters.AddWithValue("@StateID", stateID);
cmdregion.ExecuteNonQuery();
SqlDataAdapter daregion = new SqlDataAdapter(cmdregion);
DataSet dsregion = new DataSet();
daregion.Fill(dsregion);
concountry.Close();
//create list and add items in it by looping through dataset table
List<CascadingDropDownNameValue> regiondetails = new List<CascadingDropDownNameValue>();
foreach (DataRow dtrow in dsregion.Tables[0].Rows)
{
string RegionID = dtrow["RegionID"].ToString();
string RegionName = dtrow["RegionName"].ToString();
regiondetails.Add(new CascadingDropDownNameValue(RegionName, RegionID));
}
return regiondetails.ToArray();
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.Gridview
{
font-family:Verdana;
font-size:10pt;
font-weight:normal;
color:black;
}
.black_overlay{
display:none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color:black;
z-index:1001;
-moz-opacity: 0.8;
opacity:.80;
filter: alpha(opacity=80);
}
.white_content {
display:none;
position: absolute;
top: 25%;
left: 35%;
width: 25%;
padding: 0px;
border: 0px solid #a6c25c;
background-color: white;
z-index:1002;
overflow: auto;
}
.headertext{
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
color:#f19a19;
font-weight:bold;
}
</style>
<script type="text/javascript">
function ShowImages() {
document.getElementById('light').style.display = 'block';
document.getElementById('fade').style.display = 'block'
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<asp:GridView runat="server" ID="gvImages" AutoGenerateColumns="false"
DataSourceID="sqldataImages" CssClass="Gridview"
HeaderStyle-BackColor="#61A6F8">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="ImageName" HeaderText="Image Name" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:ImageButton ID="imgbtn" runat="server" ImageUrl='<%#Eval("ImagePath") %>' OnClick="imgbtn_Click"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sqldataImages" runat="server" ConnectionString="<%$ConnectionStrings:dbconnection %>"
SelectCommand="select * from ImagesPath" >
</asp:SqlDataSource>
</div>
<div id="light" class="white_content">
<table cellpadding=0 cellspacing=0 border=0 style="background-color:#a6c25c;" width="100%"><tr><tdheight="16px"><a href = "javascript:void(0)" onclick ="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'"><img src="close.gif" style="border :0px"  width="13px" align="right" height="13px"/></a></td></tr>
<tr><td style="padding-left:16px;padding-right:16px;padding-bottom:16px">
<table align="center"  border="0" cellpadding="0" cellspacing="0" style="background-color:#fff"width="100%">
<tr>
<td align="center" colspan="2" class="headertext" >Gridview Image </td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr><td align="center">
<asp:Image ID="imglightbox" runat="server"/>
</td></tr>
<tr><td height="10px"></td></tr>
</table>
</td></tr>
</table>
<div align="center" class=" headertext">
<asp:Label ID="txtlbl" runat="server"  ></asp:Label></div>
</div>
<div id="fade" class="black_overlay"></div>
</form>
</body>
</html>


protected void imgbtn_Click(object sender, EventArgs e)
{
ImageButton imgbtn = sender as ImageButton;
GridViewRow gvrow = imgbtn.NamingContainer as GridViewRow;
//Find Image button in gridview
ImageButton imgbtntxt =(ImageButton)gvrow.FindControl("imgbtn");
//Assign imagebutton url to image field in lightbox
imglightbox.ImageUrl = imgbtn.ImageUrl;
ScriptManager.RegisterStartupScript(Page, typeof(Page) , "ShowValidation", "javascript:ShowImages();",true);
}
USE [Surgere1]
GO

/****** Object:  Table [dbo].[asn]    Script Date: 04/28/2012 10:08:14 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[asn](
 [asn_id] [bigint] IDENTITY(1,1) NOT NULL,
 [client_id] [bigint] NOT NULL,
 [from_id] [bigint] NOT NULL,
 [from_type] [varchar](50) NOT NULL,
 [to_id] [bigint] NOT NULL,
 [to_type] [varchar](50) NOT NULL,
 [status] [varchar](50) NOT NULL,
 [created_id] [bigint] NULL,
 [created_dt] [datetime] NULL,
 [last_update_id] [bigint] NULL,
 [last_update_dt] [datetime] NULL,
 [asn_no] [varchar](50) NULL,
 CONSTRAINT [PK_asn] PRIMARY KEY CLUSTERED
(
 [asn_id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO
 Dim cmd As New SqlCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "sp_customer_addupdate"

            cmd.Parameters.Add("@customer_id", SqlDbType.BigInt, 0).Value = hdnId.Value
            cmd.Parameters("@customer_id").Direction = ParameterDirection.InputOutput
            cmd.Parameters.Add("@customer_name", SqlDbType.VarChar, 50).Value = txtLastName.Text & " " & txtFirstName.Text
            cmd.Parameters.Add("@description", SqlDbType.VarChar, 50, 50).Value = txtDescription.Text
            cmd.Parameters.Add("@address_1", SqlDbType.VarChar, 50).Value = txtAddr1.Text
            cmd.Parameters.Add("@address_2", SqlDbType.VarChar, 50).Value = txtAddr2.Text
            cmd.Parameters.Add("@city", SqlDbType.VarChar, 50).Value = txtCity.Text
            cmd.Parameters.Add("@state", SqlDbType.VarChar, 50).Value = txtState.Text
            cmd.Parameters.Add("@country", SqlDbType.VarChar, 50).Value = ddl_country.SelectedValue
            cmd.Parameters.Add("@zip", SqlDbType.VarChar, 50).Value = txtZip.Text
            cmd.Parameters.Add("@isdcode", SqlDbType.VarChar, 20).Value = txtisdcode.Text
            cmd.Parameters.Add("@phone", SqlDbType.VarChar, 50).Value = txtPhone.Text
            cmd.Parameters.Add("@created_id", SqlDbType.BigInt, 0).Value = Convert.ToInt64(dt.Rows(0)("user_id").ToString())
            cmd.Parameters.Add("@last_update_id", SqlDbType.BigInt, 0).Value = Convert.ToInt64(dt.Rows(0)("user_id").ToString())

            DataConnect.GetInstance.ExecuteNonQuery(cmd)
Default.aspx



<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<style type="text/css">
.modalBackground
{
background-color: Gray;
filter: alpha(opacity=80);
opacity: 0.8;
z-index: 10000;
}

.GridviewDiv {font-size: 100%; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helevetica, sans-serif; color: #303933;}
Table.Gridview{border:solid 1px #df5015;}
.Gridview th{color:#FFFFFF;border-right-color:#abb079;border-bottom-color:#abb079;padding:0.5em 0.5em 0.5em 0.5em;text-align:center}
.Gridview td{border-bottom-color:#f0f2da;border-right-color:#f0f2da;padding:0.5em 0.5em 0.5em 0.5em;}
.Gridview tr{color: Black; background-color: White; text-align:left}
:link,:visited { color: #DF4F13; text-decoration:none }

</style>
<script language="javascript" type="text/javascript">
    function closepopup() {
        $find('ModalPopupExtender1').hide();
    }
</script>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="ScriptManager1" runat="server">
</ajax:ToolkitScriptManager>
<asp:UpdatePanel ID="updatepnl1" runat="server">
<ContentTemplate>
<asp:GridView runat="server" ID="gvDetails" CssClass="Gridview"
DataKeyNames="UserId" AutoGenerateColumns="false">
<HeaderStyle BackColor="#df5015" />
<Columns>
<asp:BoundField DataField="UserName" HeaderText="UserName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btnDelete" ImageUrl="~/Images/Delete.png" runat="server" onclick="btnDelete_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Label ID="lblresult" runat="server"/>
<asp:Button ID="btnShowPopup" runat="server" style="display:none" />
<ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup"
CancelControlID="btnNo" BackgroundCssClass="modalBackground">
</ajax:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="100px" Width="400px" style="display:none">
<table width="100%" style="border:Solid 2px #D46900; width:100%; height:100%" cellpadding="0" cellspacing="0">
<tr style="background-image:url(Images/header.gif)">
<td style=" height:10%; color:White; font-weight:bold;padding:3px; font-size:larger; font-family:Calibri" align="Left">Confirm Box</td>
<td style=" color:White; font-weight:bold;padding:3px; font-size:larger" align="Right">
<a href = "javascript:void(0)" onclick = "closepopup()"><img src="Images/Close.gif" style="border :0px" align="right"/></a>
  </td>
</tr>
<tr>
<td colspan="2" align="left" style="padding:5px; font-family:Calibri">
<asp:Label ID="lblUser" runat="server"/>
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>
</td>
<td align="right" style="padding-right:15px">
<asp:ImageButton ID="btnYes" OnClick="btnYes_Click" runat="server" ImageUrl="~/Images/btnyes.jpg"/>
<asp:ImageButton ID="btnNo" runat="server" ImageUrl="~/Images/btnNo.jpg" />
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

Default.aspx.cs







using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=.;Integrated Security=true;Initial Catalog=Database");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindUserDetails();
        }
    }
    protected void BindUserDetails()
    {
        //connection open
        con.Open();
        //sql command to execute query from database
        SqlCommand cmd = new SqlCommand("Select * from UserDetails", con);
        cmd.ExecuteNonQuery();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        //Binding data to gridview
        gvDetails.DataSource = ds;
        gvDetails.DataBind();
        con.Close();
    }
  protected void btnYes_Click(object sender, ImageClickEventArgs e)
  {
      //getting userid of particular row
      int userid = Convert.ToInt32(Session["UserId"]);
      con.Open();
      SqlCommand cmd = new SqlCommand("delete from UserDetails where UserId=" + userid, con);
      int result = cmd.ExecuteNonQuery();
      con.Close();
      if (result == 1)
      {
      lblresult.Text = Session["UserName"] + " Details deleted successfully";
      lblresult.ForeColor = Color.Green;
      BindUserDetails();
      }
  }
  protected void btnDelete_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton btndetails = sender as ImageButton;
        GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;
        Session["UserId"] = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
        Session["UserName"] = gvrow.Cells[0].Text;
        lblUser.Text = "Are you sure you want to delete " + Session["UserName"] + " Details?";
        ModalPopupExtender1.Show();
    }
}