Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > BOOK: Beginning ASP.NET 4.5 : in C# and VB
|
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB 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 August 11th, 2014, 02:58 PM
Registered User
 
Join Date: Aug 2014
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default how to update Existing imag in Edit Mode. i can insert easily but unable to Edit. :'(

Sir,
i am trying "Customizing Templates of the ListView Control" in beg asp.net 4.5 and completed that exercise. but unable to update the exiting image in Edit mode.
please help.

Protected Sub EntityDataSource1_Updating(sender As Object, e As EntityDataSourceChangingEventArgs) Handles EntityDataSource1.Updating
'Dim PhotoID As Integer = Convert.ToInt32(Request.QueryString.Get("PhotoID") )

Dim PhotoID As Integer = Convert.ToInt32(Request.QueryString.Get("PhotoID") )


Dim photo As D_Photo = CType(e.Entity, D_Photo)
photo.PhotoID = PhotoID

Dim FileUpload1 As FileUpload = CType(ListView1.InsertItem.FindControl("FileUpload 1"), FileUpload)
Dim VirtualFolder As String = "~/Pics/"
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))

photo.PhotoImage = VirtualFolder + FileName + Extension

End Sub
 
Old August 12th, 2014, 03:02 PM
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,

Can you define "unable to update"? What issues are you running into?

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!
The Following User Says Thank You to Imar For This Useful Post:
Mail2vasid (August 13th, 2014)
 
Old August 13th, 2014, 08:02 AM
Registered User
 
Join Date: Aug 2014
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I mean to say I can easily insert the new image into database but I can't edit or replace the existing image.
hope you are understanding.
else provide me code for "insert edit update code for image"
I m seriously stuck....
help me
 
Old August 15th, 2014, 04:53 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Editing is not so straightforward as you need to manage the image. Here's what you could do from a high level perspective.

1. Edit the Edit template

2. Add an image control to display the current image in Edit mode

3. Add a file upload control

4. In the code behind, handle the appropriate edit command (just like you're handling events now to create the item). When the FileUpload has an image, save it to disk and update the picture with the new URL (you could also delete the old picture here first). If the FileUpload has no image, simply do nothing and leave the old URL as-is.

Hope this helps,

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 August 19th, 2014, 12:17 PM
Registered User
 
Join Date: Aug 2014
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default Please Review this code i am unable to Edit the image

>>>>>MY EDIT TEMPLATE IS<<<<<<<

<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td></td>
<td>
<asp:TextBox ID="PhotoNameTextBox" runat="server" Text='<%# BindItem.PhotoName %>' />
</td>
<td>

<asp:Image ID="Image1" runat="server" ImageUrl='<%# BindItem.Photo %>' Width="135" />
<br />
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
</EditItemTemplate>


>>> CODE BEHIND IS<<<

Protected Sub EntityDataSource1_Updating(sender As Object, e As EntityDataSourceChangingEventArgs) Handles EntityDataSource1.Updating
Dim ImageID As Integer = Convert.ToInt32(Request.QueryString.Get("ImageID") )
Dim D_Image As D_Image = CType(e.Entity, D_Image)
Dim FileUpload1 As FileUpload = CType(Listview1.InsertItem.FindControl("FileUpload 1"), FileUpload)
Dim VirtualFolder As String = "~/Pics1/"
Dim PhysicalFolder As String = Server.MapPath(VirtualFolder)
Dim Extension As String = System.IO.Path.GetExtension(FileUpload1.FileName)
Dim filename As String = Guid.NewGuid.ToString
Dim Path As String = VirtualFolder + filename + Extension
FileUpload1.SaveAs(System.IO.Path.Combine(Physical Folder, filename + Extension))
D_Image.Photo = Path.ToString
Label1.Text = D_Image.Photo
End Sub
>>>>>>>My Table IS<<

TableName=D_Image
column = ImageID int (Prmry key)
PhotoName nvarchar(256)
Photo nvarchar (256)
 
Old August 20th, 2014, 10:28 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Why are you getting the ID from the query string? You should get it from the e argument. Take a look at some of the other exercises that show you how to edit an item.

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 August 20th, 2014, 10:30 AM
Registered User
 
Join Date: Aug 2014
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default Pls pls pls pls help me to replace the existing image with new one.

help me to replace the existing image with new one.
 
Old August 20th, 2014, 10:35 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Just get the image based on its ID and the overwrite the ImageUrl property.

If you need more help, you definitely need to provide more information and a better problem description.

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 August 21st, 2014, 02:13 AM
Registered User
 
Join Date: Aug 2014
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default please i am getting furstate

i just want to replace the existing the current image with another one. like we update the existing data with another one.
or just send me the code by which i can update the image or edit the image field
 
Old August 21st, 2014, 10:53 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Once you have the picture object, just retrieve the existing URL and use that as the name of the new file.

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
Detect Edit Mode everest ASP.NET 2.0 Basics 0 December 19th, 2006 05:32 PM
Datagrid - edit mode Programator ASP.NET 1.0 and 1.1 Professional 1 September 5th, 2003 08:38 AM
Datagrid - edit mode Programator ASP.NET 1.x and 2.0 Application Design 1 September 5th, 2003 08:37 AM
Datagrid - edit mode Programator Classic ASP Professional 0 September 5th, 2003 03:13 AM





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