Hi,
I am trying to adapt the information in Chapter 13 to provide a simple file upload in a details view.
I am not using Linq - just using the info on pages 461 and on to adapt my exisiting code - perhaps that the problem?
Any way. I have :
Code:
<asp:DetailsView ID="DetailsView1"
runat="server"
Height="50px"
Width="434px"
AutoGenerateRows="False"
DataKeyNames="RecordID"
DataSourceID="SqlDataSource1"
DefaultMode="Insert" >
<Fields>
Various <asp:templatefield> entries not relevant to the problem
<asp:TemplateField HeaderText="Minutes">
<EdititemTemplate>
.................................nothing in here yet. When the Insertt works just adding the same stuff in with a sub for detailsview.itemediting???
</EdititemTemplate>
<InsertItemTemplate>
<asp:FileUpLoad id="FileUpLoad1" runat="server" />
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please select a PDF file for upload" Text="*"></asp:CustomValidator>
<asp:Button ID="cancelButton" height="20px" runat="server" CommandName="cancel" Text="Clear" CausesValidation="false" />
<asp:Button id="Button1" Text="Upload" OnClick="Button1_Click" runat="server" Height="20px" CausesValidation="False" />
</InsertItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Agenda" HeaderText="Agenda" SortExpression="Agenda" />
<asp:BoundField DataField="Newsletter" HeaderText="Newsletter" SortExpression="Newsletter" />
<asp:BoundField DataField="Directory" HeaderText="Directory" SortExpression="Directory" Visible="false" />
<asp:CommandField ShowEditButton="True" ShowInsertButton="True"/>
</Fields>
</asp:DetailsView>
My
VB code behind:
Code:
Partial Class Management_DocumentsAddEdit
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Request.QueryString.Get("Id") IsNot Nothing Then
DetailsView1.DefaultMode = DetailsViewMode.Edit
End If
End Sub
Private Sub EndEditing()
Response.Redirect("DocumentsSelect.aspx")
End Sub
Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles DetailsView1.ItemInserted
EndEditing()
End Sub
Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) Handles DetailsView1.ItemUpdated
EndEditing()
End Sub
Protected Sub Button1_Click (ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles DetailsView1.ItemInserting
Dim fileupload1 As FileUpload = CType(DetailsView1.InsertItem.FindControl("FileUpload1"), FileUpload)
If Not fileupload1.HasFile OrElse _
Not fileupload1.FileName.ToLower().EndsWith("*.pdf") Then
Dim CustomValidator1 As CustomValidator = _
CType(DetailsView1.InsertItem.findcontrol("customvalidator1"), CustomValidator)
CustomValidator1.IsValid = False
e.Cancel = True
End If
fileupload1.SaveAs(Server.MapPath("~\Members Documents\" & fileupload1.FileName))
End Sub
End Class
I am getting the following error when I use F5 to build the site:
Error 1 Argument not specified for parameter 'causesValidation' of 'Public Overridable Sub InsertItem(causesValidation As Boolean)'. C:\Websites\Cobham-ChamberOfCommerce\Management\DocumentsAddEdit.aspx .
vb 21 47 C:\Websites\Cobham-ChamberOfCommerce\
Error 2 Argument not specified for parameter 'causesValidation' of 'Public Overridable Sub InsertItem(causesValidation As Boolean)'. C:\Websites\Cobham-ChamberOfCommerce\Management\DocumentsAddEdit.aspx .
vb 25 23 C:\Websites\Cobham-ChamberOfCommerce\
I saw the bit in para 4 about setting 'causes validation' to false for the cancel button but I do not have a cancel button?
If I get this to work I plan to replicate it for the Agenda and Newsletter fields in the details view.
Do I need to use Fileupload2 and FileUpload3 and have separate subs for them in the code behind page?