Imports System.Data
Imports MySql.Data.MySqlClient

Partial Class FormView1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		IF Not Page.IsPostBack() Then
			BindData()
		End IF
    End Sub

    Sub BindData()

		Dim objConn As MySqlConnection
		Dim objCmd As MySqlCommand
		Dim dtAdapter As New MySqlDataAdapter 
        Dim strConnString As String
        strConnString = "Server=localhost;User Id=root; Password=root; Database=mydatabase; Pooling=false"
        objConn = New MySqlConnection(strConnString)
        objConn.Open()

        Dim strSQL As String
		Dim ds As New DataSet
        strSQL = "SELECT * FROM gallery "
		objCmd = New MySqlCommand
		With objCmd
			.Connection = objConn
			.CommandText = strSQL			
			.CommandType = CommandType.Text
		End With
		dtAdapter.SelectCommand = objCmd

		dtAdapter.Fill(ds)

		'*** BindData to FormView ***'
		myFormView.DataSource = ds
		myFormView.DataBind()
		
		ds = Nothing

        objConn.Close()
        objConn = Nothing

    End Sub

    Protected Sub myFormView_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles myFormView.DataBound
        '*** Image ***'
        Dim Image1 As Image = CType(myFormView.FindControl("Image1"), Image)
        If Not IsNothing(Image1) Then
            Image1.ImageUrl = "images/" & myFormView.DataItem("Picture")
            Image1.Attributes.Add("OnClick", "window.open('images/" & myFormView.DataItem("Picture") & "')")
            Image1.Style.Add("cursor", "hand")
            Image1.ToolTip = myFormView.DataItem("GalleryName")
        End If

        '*** GalleryName ***'
        Dim lblGalleryName As Label = CType(myFormView.FindControl("lblGalleryName"), Label)
        If Not IsNothing(lblGalleryName) Then
            lblGalleryName.Text = myFormView.DataItem("GalleryName")
        End If
    End Sub

   Protected Sub myFormView_PageIndexChanging(ByVal sender As Object, ByVal e As FormViewPageEventArgs) Handles myFormView.PageIndexChanging
		myFormView.PageIndex = e.NewPageIndex
		BindData()
   End Sub

End Class