A
Admin
Hi there
I have the ascx UC below being dynamically injected into another ascx
UC which is then dynamically injected into an aspx page. Using
page.loadcontrol syntax.
My problem is the datagrid doesn't refresh until i hit the browser
refresh button. And then if i was doing an add i get two records added
to my databse.
I know from debugging that my databinding code is being hit and that
my Db is being updated on my first click - but the damn datagrid does
n't refresh even when i set its datasource to nothing and then rebind
it.
Any help would be greatly appreciated. Is this a setting, is it the
ascx insode and ascx inside an aspx, or somewthing else.
TIA
Henry
' =========================================================================
Imports System.IO
Imports System.Drawing
Imports System.Diagnostics
Imports System.Globalization
Public Class AddEditEditions
Inherits System.Web.UI.UserControl
Protected dsList As New DataSet
Protected dsPubs As New DataSet
Protected WithEvents lblImageCaption As
System.Web.UI.WebControls.Label
Protected WithEvents txtPrintDate As
System.Web.UI.WebControls.TextBox
Protected WithEvents cmdEditCover As
System.Web.UI.WebControls.ImageButton
Protected WithEvents lblEditionSizeCaption As
System.Web.UI.WebControls.Label
Protected WithEvents lblEditionSize As
System.Web.UI.WebControls.Label
Protected WithEvents cmdEditEdition As
System.Web.UI.WebControls.ImageButton
Protected WithEvents lblUploadEdition As
System.Web.UI.WebControls.Label
Protected WithEvents txtEdition As
System.Web.UI.HtmlControls.HtmlInputFile
Protected WithEvents cboPublications As
System.Web.UI.WebControls.DropDownList
Protected WithEvents pnlUploadEdition As
System.Web.UI.WebControls.Panel
Protected WithEvents txtKeywords As System.Web.UI.WebControls.TextBox
Protected WithEvents lblNoCover As System.Web.UI.WebControls.Label
Protected WithEvents lblFileError As System.Web.UI.WebControls.Label
Private _EditCover As Boolean
Protected WithEvents regEx_PrintDate As
System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents ValidationSummary1 As
System.Web.UI.WebControls.ValidationSummary
Protected WithEvents req_Title As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents req_Date As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents pnlUploadCover As
System.Web.UI.WebControls.Panel
Protected WithEvents lblUploadCover As
System.Web.UI.WebControls.Label
Private _EditDownload As Boolean
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents txtBlurb As System.Web.UI.WebControls.TextBox
Protected WithEvents txtName As System.Web.UI.WebControls.TextBox
Protected WithEvents cmdAdd As System.Web.UI.WebControls.Button
Protected WithEvents cmdUpdate As System.Web.UI.WebControls.Button
Protected WithEvents dgList As System.Web.UI.WebControls.DataGrid
Protected WithEvents lblImageName As System.Web.UI.WebControls.Label
Protected WithEvents txtImage As
System.Web.UI.HtmlControls.HtmlInputFile
'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindPubs()
End If
Me.lblNoCover.Visible = False
Me.lblFileError.Visible = False
End Sub
' ===================================================================================
' Purpose :
' ===================================================================================
Private Function GetCoverPath(ByVal ImagePath As String) As String
If ImagePath.Length = 0 Then
Return String.Empty
Else
Return Path.GetFileName(ImagePath)
End If
End Function
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub BindPubs()
dsPubs = AdminDb.GetPublications
Me.cboPublications.DataSource = dsPubs
Me.cboPublications.DataMember = dsPubs.Tables(0).TableName
Me.cboPublications.DataValueField = "PubId"
Me.cboPublications.DataTextField = "PubName"
Me.cboPublications.DataBind()
dsList = AdminDb.GetEditions
Me.dgList.DataSource = dsList
dgList.DataKeyField = "EdId"
dgList.DataBind()
End Sub
' ===================================================================================
' Purpose :
' ===================================================================================
Protected Function GetPubName(ByVal pubId As Long) As String
Try
Dim dr() As DataRow
dr = dsPubs.Tables(0).Select("PubId=" & pubId)
If dr.Length > 0 Then
Return CType(dr(0)("PubName"), String)
End If
Catch e As Exception
Debug.WriteLine(e.Message)
End Try
Return String.Empty
End Function
#Region "Sub : ResetUI "
' ===================================================================================
' Purpose : Resets the user interface
' ===================================================================================
Private Sub ResetUI()
Me.txtName.Text = String.Empty
Me.txtBlurb.Text = String.Empty
Me.txtPrintDate.Text = String.Empty
Me.txtKeywords.Text = String.Empty
Me.cmdAdd.Visible = True
Me.cmdUpdate.Visible = False
Me.lblImageCaption.Visible = False
Me.lblImageName.Visible = False
Me.lblEditionSize.Visible = False
Me.lblEditionSizeCaption.Visible = False
Me.cmdEditCover.Visible = False
Me.cmdEditEdition.Visible = False
Me.pnlUploadEdition.Visible = True
Me.lblUploadEdition.Visible = True
Me.pnlUploadCover.Visible = True
Me.lblUploadCover.Visible = True
End Sub
#End Region
#Region "Sub : cmdAdd "
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAdd.Click
Dim ei As New AdminDb.EditionInfo
Threading.Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture("en-NZ")
If (Me.txtImage.PostedFile Is Nothing) OrElse
(Me.txtImage.PostedFile.ContentLength = 0) Then
Me.lblNoCover.Visible = True
ElseIf (Me.txtEdition.PostedFile Is Nothing) OrElse
(Me.txtEdition.PostedFile.ContentLength = 0) Then
Me.lblFileError.Visible = True
Else
ei.EdName = Me.txtName.Text
ei.PubId = Me.cboPublications.SelectedValue
ei.PrintDate = CType(Me.txtPrintDate.Text, Date)
ei.Blurb = Me.txtBlurb.Text
ei.CoverPath = GetCoverPath(Me.txtImage.Value)
ei.CoverImage = GetBytes(Me.txtImage.PostedFile)
ei.Keywords = Me.txtKeywords.Text
ei.Download = GetBytes(Me.txtEdition.PostedFile)
ei.FileSize = ei.Download.Length
ei.ContentType = Me.txtEdition.PostedFile.ContentType
ei.FileName = Path.GetFileName(Me.txtEdition.PostedFile.FileName)
AdminDb.AddEdInfo(ei)
ResetUI()
BindPubs()
Response.Redirect("~/DesktopDefault.aspx?tabid=-1&fxId=3")
End If
End Sub
#End Region
#Region "Sub : cmdUpdate "
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdUpdate.Click
Dim ei As New AdminDb.EditionInfo
ei.EdId = CType(viewstate.Item("edId"), Long)
ei.PubId = Me.cboPublications.SelectedValue
ei.PrintDate = CType(Me.txtPrintDate.Text, Date)
ei.EdName = Me.txtName.Text
ei.Blurb = Me.txtBlurb.Text
ei.Keywords = Me.txtKeywords.Text
' Update cover
If Not (viewstate.Item("editCoverOn") Is Nothing) AndAlso _
(CType(viewstate.Item("editCoverOn"), Boolean)) Then
ei.CoverPath = GetCoverPath(Me.txtImage.Value)
ei.CoverImage = GetBytes(Me.txtImage.PostedFile)
AdminDb.UpdateEdCover(ei)
End If
' Update download
If Not (viewstate.Item("editDownloadOn") Is Nothing) AndAlso _
(CType(viewstate.Item("editDownloadOn"), Boolean)) Then
ei.Download = GetBytes(Me.txtEdition.PostedFile)
ei.FileSize = ei.Download.Length
ei.ContentType = Me.txtEdition.PostedFile.ContentType
ei.FileName = Path.GetFileName(Me.txtEdition.PostedFile.FileName)
AdminDb.UpdateEdDownload(ei)
End If
AdminDb.UpdateEdHeaderInfo(ei)
ResetUI()
BindPubs()
End Sub
#End Region
#Region "Sub : SetUpUpdate "
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub SetUpUpdate(ByVal edId As Int32)
Dim dr() As DataRow
dr = dsList.Tables(0).Select("EdId=" & edId)
If dr.Length > 0 Then
Me.txtName.Text = CType(dr(0)(1), String)
Me.cboPublications.SelectedValue = CType(dr(0)(2), String)
Me.txtPrintDate.Text = CType(dr(0)("PrintDate"), String)
If Not IsDBNull(dr(0)(4)) Then
Me.txtBlurb.Text = CType(dr(0)("Blurb"), String)
End If
' Display Cover label/ upload
If IsDBNull(dr(0)(5)) OrElse (CStr(dr(0)(5)) = String.Empty) Then
Me.lblUploadCover.Visible = False
Me.pnlUploadCover.Visible = False
Me.lblImageName.Text = "No associated cover image."
Else
Me.lblUploadCover.Visible = _EditCover
Me.pnlUploadCover.Visible = _EditCover
Me.lblImageName.Text = CType(dr(0)(5), String)
End If
Me.lblImageCaption.Visible = True
Me.lblImageName.Visible = True
Me.cmdEditCover.Visible = True
' Display download label/ upload
Dim strFileSize As String
strFileSize = Math.Round((CInt(dr(0)("DownloadFileSize")) / 1024),
0).ToString & "Kb"
Me.lblEditionSize.Text = CStr(dr(0)("DownloadFileName")) & " : (" &
strFileSize & ")"
Me.lblEditionSizeCaption.Visible = True
Me.lblEditionSize.Visible = True
Me.cmdEditEdition.Visible = True
Me.lblUploadEdition.Visible = _EditDownload
Me.pnlUploadEdition.Visible = _EditDownload
If Not IsDBNull(dr(0)("Keywords")) Then
Me.txtKeywords.Text = CType(dr(0)("Keywords"), String)
End If
Me.cmdUpdate.Visible = True
Me.cmdAdd.Visible = False
End If
End Sub
#End Region
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub cmdEditCover_Click(ByVal sender As System.Object, ByVal e
As System.Web.UI.ImageClickEventArgs) Handles cmdEditCover.Click
BindPubs()
_EditCover = True
viewstate.Add("editCoverOn", True)
SetUpUpdate(CInt(viewstate.Item("edId")))
End Sub
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub cmdEditEdition_Click(ByVal sender As System.Object, ByVal
e As System.Web.UI.ImageClickEventArgs) Handles cmdEditEdition.Click
BindPubs()
_EditDownload = True
viewstate.Add("editDownloadOn", True)
SetUpUpdate(CInt(viewstate.Item("edId")))
End Sub
#Region "Function : GetBytes "
' ===================================================================================
' Purpose : Breaks a passed HttpPostedFile in a bytes array.
' Primarily used when inserting uploaded files into a database.
' ===================================================================================
Private Function GetBytes(ByVal postedFile As HttpPostedFile) As
Byte()
Dim fReader As BinaryReader
Dim fWriter As BinaryWriter
Dim bufferSize As Int32 = 4096
Dim byteCount As Int32
Dim fLocalStream As New MemoryStream
Dim fBytes() As Byte
Try
fReader = New BinaryReader(postedFile.InputStream)
fWriter = New BinaryWriter(fLocalStream)
' Upload file
Do
fBytes = fReader.ReadBytes(bufferSize)
byteCount = fBytes.Length
fWriter.Write(fBytes)
fWriter.Flush()
Loop Until byteCount = 0
' return image
Return fLocalStream.GetBuffer
Catch e As Exception
Debug.WriteLine(e.Message)
Finally
If Not (fWriter Is Nothing) Then
fWriter.Close()
End If
If Not (fReader Is Nothing) Then
fReader.Close()
End If
End Try
End Function
#End Region
' ===================================================================================
' Purpose : Delete a publication from the database.
' ===================================================================================
Private Sub dgList_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgList.DeleteCommand
Dim edId As Long = CLng(dgList.DataKeys(e.Item.ItemIndex))
' Delete Role
AdminDb.DeleteEdInfo(edId)
' UnSelect row for editing
dgList.EditItemIndex = -1
ResetUI()
BindPubs()
End Sub 'RoleList_DeleteCommand
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub dgList_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgList.UpdateCommand
ResetUI()
BindPubs()
Dim edId As Long = CLng(dgList.DataKeys(e.Item.ItemIndex))
Me.dgList.SelectedIndex = e.Item.ItemIndex
viewstate.Add("edId", edId)
SetUpUpdate(edId)
End Sub
' ===================================================================================
' Purpose : Inserts the date of creation of the publication into one
of the
' datagrid cells.
' ===================================================================================
Private Sub dgList_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgList.ItemCreated
If e.Item.DataItem Is Nothing Then Return
e.Item.Cells(1).Text = DataBinder.Eval(e.Item.DataItem, "PrintDate",
"{0:d}")
Dim pubId As Long = DataBinder.Eval(e.Item.DataItem, "PubId")
e.Item.Cells(2).Text = GetPubName(pubId)
End Sub
End Class
I have the ascx UC below being dynamically injected into another ascx
UC which is then dynamically injected into an aspx page. Using
page.loadcontrol syntax.
My problem is the datagrid doesn't refresh until i hit the browser
refresh button. And then if i was doing an add i get two records added
to my databse.
I know from debugging that my databinding code is being hit and that
my Db is being updated on my first click - but the damn datagrid does
n't refresh even when i set its datasource to nothing and then rebind
it.
Any help would be greatly appreciated. Is this a setting, is it the
ascx insode and ascx inside an aspx, or somewthing else.
TIA
Henry
' =========================================================================
Imports System.IO
Imports System.Drawing
Imports System.Diagnostics
Imports System.Globalization
Public Class AddEditEditions
Inherits System.Web.UI.UserControl
Protected dsList As New DataSet
Protected dsPubs As New DataSet
Protected WithEvents lblImageCaption As
System.Web.UI.WebControls.Label
Protected WithEvents txtPrintDate As
System.Web.UI.WebControls.TextBox
Protected WithEvents cmdEditCover As
System.Web.UI.WebControls.ImageButton
Protected WithEvents lblEditionSizeCaption As
System.Web.UI.WebControls.Label
Protected WithEvents lblEditionSize As
System.Web.UI.WebControls.Label
Protected WithEvents cmdEditEdition As
System.Web.UI.WebControls.ImageButton
Protected WithEvents lblUploadEdition As
System.Web.UI.WebControls.Label
Protected WithEvents txtEdition As
System.Web.UI.HtmlControls.HtmlInputFile
Protected WithEvents cboPublications As
System.Web.UI.WebControls.DropDownList
Protected WithEvents pnlUploadEdition As
System.Web.UI.WebControls.Panel
Protected WithEvents txtKeywords As System.Web.UI.WebControls.TextBox
Protected WithEvents lblNoCover As System.Web.UI.WebControls.Label
Protected WithEvents lblFileError As System.Web.UI.WebControls.Label
Private _EditCover As Boolean
Protected WithEvents regEx_PrintDate As
System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents ValidationSummary1 As
System.Web.UI.WebControls.ValidationSummary
Protected WithEvents req_Title As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents req_Date As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents pnlUploadCover As
System.Web.UI.WebControls.Panel
Protected WithEvents lblUploadCover As
System.Web.UI.WebControls.Label
Private _EditDownload As Boolean
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents txtBlurb As System.Web.UI.WebControls.TextBox
Protected WithEvents txtName As System.Web.UI.WebControls.TextBox
Protected WithEvents cmdAdd As System.Web.UI.WebControls.Button
Protected WithEvents cmdUpdate As System.Web.UI.WebControls.Button
Protected WithEvents dgList As System.Web.UI.WebControls.DataGrid
Protected WithEvents lblImageName As System.Web.UI.WebControls.Label
Protected WithEvents txtImage As
System.Web.UI.HtmlControls.HtmlInputFile
'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindPubs()
End If
Me.lblNoCover.Visible = False
Me.lblFileError.Visible = False
End Sub
' ===================================================================================
' Purpose :
' ===================================================================================
Private Function GetCoverPath(ByVal ImagePath As String) As String
If ImagePath.Length = 0 Then
Return String.Empty
Else
Return Path.GetFileName(ImagePath)
End If
End Function
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub BindPubs()
dsPubs = AdminDb.GetPublications
Me.cboPublications.DataSource = dsPubs
Me.cboPublications.DataMember = dsPubs.Tables(0).TableName
Me.cboPublications.DataValueField = "PubId"
Me.cboPublications.DataTextField = "PubName"
Me.cboPublications.DataBind()
dsList = AdminDb.GetEditions
Me.dgList.DataSource = dsList
dgList.DataKeyField = "EdId"
dgList.DataBind()
End Sub
' ===================================================================================
' Purpose :
' ===================================================================================
Protected Function GetPubName(ByVal pubId As Long) As String
Try
Dim dr() As DataRow
dr = dsPubs.Tables(0).Select("PubId=" & pubId)
If dr.Length > 0 Then
Return CType(dr(0)("PubName"), String)
End If
Catch e As Exception
Debug.WriteLine(e.Message)
End Try
Return String.Empty
End Function
#Region "Sub : ResetUI "
' ===================================================================================
' Purpose : Resets the user interface
' ===================================================================================
Private Sub ResetUI()
Me.txtName.Text = String.Empty
Me.txtBlurb.Text = String.Empty
Me.txtPrintDate.Text = String.Empty
Me.txtKeywords.Text = String.Empty
Me.cmdAdd.Visible = True
Me.cmdUpdate.Visible = False
Me.lblImageCaption.Visible = False
Me.lblImageName.Visible = False
Me.lblEditionSize.Visible = False
Me.lblEditionSizeCaption.Visible = False
Me.cmdEditCover.Visible = False
Me.cmdEditEdition.Visible = False
Me.pnlUploadEdition.Visible = True
Me.lblUploadEdition.Visible = True
Me.pnlUploadCover.Visible = True
Me.lblUploadCover.Visible = True
End Sub
#End Region
#Region "Sub : cmdAdd "
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAdd.Click
Dim ei As New AdminDb.EditionInfo
Threading.Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture("en-NZ")
If (Me.txtImage.PostedFile Is Nothing) OrElse
(Me.txtImage.PostedFile.ContentLength = 0) Then
Me.lblNoCover.Visible = True
ElseIf (Me.txtEdition.PostedFile Is Nothing) OrElse
(Me.txtEdition.PostedFile.ContentLength = 0) Then
Me.lblFileError.Visible = True
Else
ei.EdName = Me.txtName.Text
ei.PubId = Me.cboPublications.SelectedValue
ei.PrintDate = CType(Me.txtPrintDate.Text, Date)
ei.Blurb = Me.txtBlurb.Text
ei.CoverPath = GetCoverPath(Me.txtImage.Value)
ei.CoverImage = GetBytes(Me.txtImage.PostedFile)
ei.Keywords = Me.txtKeywords.Text
ei.Download = GetBytes(Me.txtEdition.PostedFile)
ei.FileSize = ei.Download.Length
ei.ContentType = Me.txtEdition.PostedFile.ContentType
ei.FileName = Path.GetFileName(Me.txtEdition.PostedFile.FileName)
AdminDb.AddEdInfo(ei)
ResetUI()
BindPubs()
Response.Redirect("~/DesktopDefault.aspx?tabid=-1&fxId=3")
End If
End Sub
#End Region
#Region "Sub : cmdUpdate "
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdUpdate.Click
Dim ei As New AdminDb.EditionInfo
ei.EdId = CType(viewstate.Item("edId"), Long)
ei.PubId = Me.cboPublications.SelectedValue
ei.PrintDate = CType(Me.txtPrintDate.Text, Date)
ei.EdName = Me.txtName.Text
ei.Blurb = Me.txtBlurb.Text
ei.Keywords = Me.txtKeywords.Text
' Update cover
If Not (viewstate.Item("editCoverOn") Is Nothing) AndAlso _
(CType(viewstate.Item("editCoverOn"), Boolean)) Then
ei.CoverPath = GetCoverPath(Me.txtImage.Value)
ei.CoverImage = GetBytes(Me.txtImage.PostedFile)
AdminDb.UpdateEdCover(ei)
End If
' Update download
If Not (viewstate.Item("editDownloadOn") Is Nothing) AndAlso _
(CType(viewstate.Item("editDownloadOn"), Boolean)) Then
ei.Download = GetBytes(Me.txtEdition.PostedFile)
ei.FileSize = ei.Download.Length
ei.ContentType = Me.txtEdition.PostedFile.ContentType
ei.FileName = Path.GetFileName(Me.txtEdition.PostedFile.FileName)
AdminDb.UpdateEdDownload(ei)
End If
AdminDb.UpdateEdHeaderInfo(ei)
ResetUI()
BindPubs()
End Sub
#End Region
#Region "Sub : SetUpUpdate "
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub SetUpUpdate(ByVal edId As Int32)
Dim dr() As DataRow
dr = dsList.Tables(0).Select("EdId=" & edId)
If dr.Length > 0 Then
Me.txtName.Text = CType(dr(0)(1), String)
Me.cboPublications.SelectedValue = CType(dr(0)(2), String)
Me.txtPrintDate.Text = CType(dr(0)("PrintDate"), String)
If Not IsDBNull(dr(0)(4)) Then
Me.txtBlurb.Text = CType(dr(0)("Blurb"), String)
End If
' Display Cover label/ upload
If IsDBNull(dr(0)(5)) OrElse (CStr(dr(0)(5)) = String.Empty) Then
Me.lblUploadCover.Visible = False
Me.pnlUploadCover.Visible = False
Me.lblImageName.Text = "No associated cover image."
Else
Me.lblUploadCover.Visible = _EditCover
Me.pnlUploadCover.Visible = _EditCover
Me.lblImageName.Text = CType(dr(0)(5), String)
End If
Me.lblImageCaption.Visible = True
Me.lblImageName.Visible = True
Me.cmdEditCover.Visible = True
' Display download label/ upload
Dim strFileSize As String
strFileSize = Math.Round((CInt(dr(0)("DownloadFileSize")) / 1024),
0).ToString & "Kb"
Me.lblEditionSize.Text = CStr(dr(0)("DownloadFileName")) & " : (" &
strFileSize & ")"
Me.lblEditionSizeCaption.Visible = True
Me.lblEditionSize.Visible = True
Me.cmdEditEdition.Visible = True
Me.lblUploadEdition.Visible = _EditDownload
Me.pnlUploadEdition.Visible = _EditDownload
If Not IsDBNull(dr(0)("Keywords")) Then
Me.txtKeywords.Text = CType(dr(0)("Keywords"), String)
End If
Me.cmdUpdate.Visible = True
Me.cmdAdd.Visible = False
End If
End Sub
#End Region
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub cmdEditCover_Click(ByVal sender As System.Object, ByVal e
As System.Web.UI.ImageClickEventArgs) Handles cmdEditCover.Click
BindPubs()
_EditCover = True
viewstate.Add("editCoverOn", True)
SetUpUpdate(CInt(viewstate.Item("edId")))
End Sub
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub cmdEditEdition_Click(ByVal sender As System.Object, ByVal
e As System.Web.UI.ImageClickEventArgs) Handles cmdEditEdition.Click
BindPubs()
_EditDownload = True
viewstate.Add("editDownloadOn", True)
SetUpUpdate(CInt(viewstate.Item("edId")))
End Sub
#Region "Function : GetBytes "
' ===================================================================================
' Purpose : Breaks a passed HttpPostedFile in a bytes array.
' Primarily used when inserting uploaded files into a database.
' ===================================================================================
Private Function GetBytes(ByVal postedFile As HttpPostedFile) As
Byte()
Dim fReader As BinaryReader
Dim fWriter As BinaryWriter
Dim bufferSize As Int32 = 4096
Dim byteCount As Int32
Dim fLocalStream As New MemoryStream
Dim fBytes() As Byte
Try
fReader = New BinaryReader(postedFile.InputStream)
fWriter = New BinaryWriter(fLocalStream)
' Upload file
Do
fBytes = fReader.ReadBytes(bufferSize)
byteCount = fBytes.Length
fWriter.Write(fBytes)
fWriter.Flush()
Loop Until byteCount = 0
' return image
Return fLocalStream.GetBuffer
Catch e As Exception
Debug.WriteLine(e.Message)
Finally
If Not (fWriter Is Nothing) Then
fWriter.Close()
End If
If Not (fReader Is Nothing) Then
fReader.Close()
End If
End Try
End Function
#End Region
' ===================================================================================
' Purpose : Delete a publication from the database.
' ===================================================================================
Private Sub dgList_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgList.DeleteCommand
Dim edId As Long = CLng(dgList.DataKeys(e.Item.ItemIndex))
' Delete Role
AdminDb.DeleteEdInfo(edId)
' UnSelect row for editing
dgList.EditItemIndex = -1
ResetUI()
BindPubs()
End Sub 'RoleList_DeleteCommand
' ===================================================================================
' Purpose :
' ===================================================================================
Private Sub dgList_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgList.UpdateCommand
ResetUI()
BindPubs()
Dim edId As Long = CLng(dgList.DataKeys(e.Item.ItemIndex))
Me.dgList.SelectedIndex = e.Item.ItemIndex
viewstate.Add("edId", edId)
SetUpUpdate(edId)
End Sub
' ===================================================================================
' Purpose : Inserts the date of creation of the publication into one
of the
' datagrid cells.
' ===================================================================================
Private Sub dgList_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgList.ItemCreated
If e.Item.DataItem Is Nothing Then Return
e.Item.Cells(1).Text = DataBinder.Eval(e.Item.DataItem, "PrintDate",
"{0:d}")
Dim pubId As Long = DataBinder.Eval(e.Item.DataItem, "PubId")
e.Item.Cells(2).Text = GetPubName(pubId)
End Sub
End Class