Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 17th, 2008, 04:50 AM
Authorized User
 
Join Date: Apr 2008
Posts: 25
Thanks: 0
Thanked 1 Time in 1 Post
Default

Sorry, I don't get it. The other fields, like LastName and FirstName, are not updated when I click on 'Update'. I do not need to do anything on them?

Please advise. Thanks.

 
Old June 17th, 2008, 05:11 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You haven't posted the code for the DetailsView or the SqlDataSource control so I can't tell for sure what the problem is.

However, as explained in my book those controls work together. The DetailsView provides values for the SqlDataSource control which uses that info to insert or update the database.

If that doesn't work, I'd start with that. Add those controls to the page (as explained in the book) and see if it works. If it does, make changes to the events of the DetailsView in order to save the uploaded file. If that works, provide the PictureUrl to the NewValues collection.

Again, this is all in my book; you're not doing much different stuff than I have in my code, so rereading the relevant sections might help you understand how this works.

Cheers,

Imar
 
Old December 2nd, 2009, 12:38 AM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Same kind of problem

I'm having the same kind of problem I believe... I'm currently due to exam and we have been using your book for learning - I'm not sure how capable our teacher is here at eCademy. with only a few days left before exam i really need this question sorted out... our teacher is of no help.

my problem: i have a details view which will only be used for inserting data. i have a fileupload control for uploading images and the meaning is that the pictures url should be stored in the database. as the fileupload does not have "value" field how can i get the url into the db?

the file upload works great but i get a error with inserting null (which is right because i dont want nulls in the db)
since the fileupload cant handle a value item i've been trying to get the url into an hidden texbox as you can see in the code but with no luck.

i also tried from your book at around page 419 and still no clue... as i said time is of essence and i would appreciate if you could help me out here:

my aspx code:
<asp:DetailsView ID="DetailsView1" runat="server"
DataSourceID="dvDS" DataKeyNames="prodID" AutoGenerateRows="False"
DefaultMode="Insert">
<Fields>
<asp:BoundField DataField="prodID" HeaderText="prodID" InsertVisible="False" ReadOnly="True" SortExpression="prodID" />
<asp:TemplateField HeaderText="SubID" SortExpression="SubID">
<InsertItemTemplate>
<asp:DropDownList ID="ddlSubCategory" runat="server" DataSourceID="SqlDataSource1" DataTextField="subName" DataValueField="subID" SelectedValue='<%# Bind("SubID") %>' >
<asp:ListItem Value="">Make a choice!</asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="prodName" HeaderText="prodName" SortExpression="prodName" />
<asp:BoundField DataField="prodTxt" HeaderText="prodTxt" SortExpression="prodTxt" />
<asp:BoundField DataField="prodPrice" HeaderText="prodPrice" SortExpression="prodPrice" />
<asp:TemplateField HeaderText="prodIMG" SortExpression="prodIMG">
<InsertItemTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:TextBox ID="tbxFile" runat="server" Visible="false" ReadOnly="True" Text='<%# Bind("prodIMG") %>'></asp:TextBox>
<%--<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("prodIMG") %>'></asp:TextBox>--%>
</InsertItemTemplate>
</asp:TemplateField>

<asp:CommandField ShowInsertButton="True" CausesValidation="false"/>
</Fields>
</asp:DetailsView>

<asp:SqlDataSource ID="dvDS" runat="server" ConnectionString="<%$ ConnectionStrings:csShop %>"
InsertCommand="INSERT INTO [Products] ([SubID], [prodName], [prodTxt], [prodPrice], [prodIMG], [prodDate]) VALUES (@SubID, @prodName, @prodTxt, @prodPrice, @prodIMG, GETDATE())">
<InsertParameters>
<asp:Parameter Name="SubID" Type="Int32" />
<asp:Parameter Name="prodName" Type="String" />
<asp:Parameter Name="prodTxt" Type="String" />
<asp:Parameter Name="prodPrice" Type="Decimal" />
<asp:Parameter Name="prodIMG" Type="String" />

</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:csShop %>"
SelectCommand="SELECT [subID], [subName] FROM [SubCategory]">
</asp:SqlDataSource>

and my vb code:
Protected Sub dvDS_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEven tArgs) Handles dvDS.Inserting

Dim FileUpload1 As FileUpload = CType(DetailsView1.FindControl("FileUpload1"), FileUpload)
Dim virtualFolder As String = "~/productimages/"
Dim physicalFolder As String = Server.MapPath(virtualFolder)
Dim fileName As String = Guid.NewGuid().ToString()
Dim extension As String = System.IO.Path.GetExtension(FileUpload1.FileName)

FileUpload1.SaveAs(System.IO.Path.Combine(physical Folder, fileName + extension))

'Dim myPicture As String = virtualFolder + fileName + extension
'lblURL.Text
'dvDS.InsertParameters.Item("prodIMG").DefaultValu e = myPicture
'e.Values["prodIMG"] = virtualFolder + fileName + extension

'Dim FileCtrl As FileUpload = CType(DetailsView1.Controls(0).FindControl("FileUp load1"), FileUpload)
Dim TextCtrl As TextBox = CType(DetailsView1.Controls(0).FindControl("tbxFil e"), TextBox)
'If FileCtrl.HasFile Then
Dim url As String = virtualFolder + fileName + extension
'FileCtrl.SaveAs(Server.MapPath(FileName))
TextCtrl.Text = url
TextCtrl.Visible = True
'FileCtrl.Visible = False
'End If

End Sub
 
Old December 2nd, 2009, 05:32 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Take a look at the Try It Out on page 460. You'll see how to save a file and build up a path. Then you can assign that path to e.Values["prodIMG"] (whcih you currently have commented out).

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 2nd, 2009, 09:21 AM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there

the tryout on page 460 is the one i started out with - but if i use the e.value then i get an answer that its not a member of System.Web.UI.WebControls.SqlDataSourceCommandEven tArgs.
also that tryout uses Linq - which im not.
 
Old December 2nd, 2009, 10:06 AM
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

After 72 hours of pain i actually managed to solve this
I had to move the code to detailsview_iteminserting - the right code was:

Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventAr gs) Handles DetailsView1.ItemInserting

Dim FileUpload1 As FileUpload = CType(DetailsView1.FindControl("FileUpload1"), FileUpload)
Dim virtualFolder As String = "~/productimages/"
Dim physicalFolder As String = Server.MapPath(virtualFolder)
Dim fileName As String = Guid.NewGuid().ToString()
Dim extension As String = System.IO.Path.GetExtension(FileUpload1.FileName)
'Upload file:
FileUpload1.SaveAs(System.IO.Path.Combine(physical Folder, fileName + extension))
'Assign url to db:
e.Values("prodIMG") = virtualFolder + fileName + extension

End Sub
 
Old December 2nd, 2009, 10:10 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Great; glad it's working now..... ;-)

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter File Types in ASP.NET File Upload ramuis78 ASP.NET 2.0 Basics 2 May 31st, 2007 10:50 AM
Whole Folder upload(Multi file Upload) ramasamy_rams XML 1 September 9th, 2005 12:43 PM
JSP file upload and delete file pandjie JSP Basics 0 January 29th, 2005 10:49 PM
Upload file hbcontract XML 2 November 6th, 2003 07:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.