473,659 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DetailsView image update trouble.(Urgent help needed)


Hello,
I have an image file name in a table that a let users modify via a
GridView/DetailView pair.

* The actual image file is saved in the image folder of the application.
But the image is rendered in a templatefield 's <itemtemplate > on the
detailsview.
In the <edititemtempla te> i have a fileupload control . leting users upload
a new picture and thus replace the old one.

I use the new two ways databinding feature Bind(..... for the data update.

the problem here here when a field other then the image is updated , then my
image filename is set to its default value (NULL).
I dont want that. When the picture is not updated on the detailsView, it
should keep its default value.
How can i achieve this. I have now spende more then 10 hours on trying to
achieve this and i therefore need some fresh thought here.

Many thanks in advance

JJ

Mar 30 '06 #1
4 6312
The field is probably not re-setting to it's default value it is being set
to the value of the control, which if the user doesn't select a new file to
upload, is presumably null.

The answer is to populate the control that is bound to the image filename
field, with the image filename automatically so that if the user does not
select a new value for that control then it will update the field to the same
value that is in it already.

If you could post your code I might be able to give you more specific advice.

"jens Jensen" wrote:

Hello,
I have an image file name in a table that a let users modify via a
GridView/DetailView pair.

* The actual image file is saved in the image folder of the application.
But the image is rendered in a templatefield 's <itemtemplate > on the
detailsview.
In the <edititemtempla te> i have a fileupload control . leting users upload
a new picture and thus replace the old one.

I use the new two ways databinding feature Bind(..... for the data update.

the problem here here when a field other then the image is updated , then my
image filename is set to its default value (NULL).
I dont want that. When the picture is not updated on the detailsView, it
should keep its default value.
How can i achieve this. I have now spende more then 10 hours on trying to
achieve this and i therefore need some fresh thought here.

Many thanks in advance

JJ

Mar 30 '06 #2
<asp:TemplateFi eld HeaderText="Ima ge">

<itemtemplate >

<asp:Image ImageUrl='<%# Eval("pic", "../admin/images/{0}" ) %>'
runat="server" ID="image" />

</itemtemplate>

<EditItemTempla te>
<asp:FileUplo ad ID="fileUpload1 " runat="server" />

</EditItemTemplat e>

</asp:TemplateFie ld>
</Fields>

update event handler

.........

FileUpload fileUpload = ((DetailsView)s ender).FindCont rol("FileUpload 1") as
FileUpload;

if (fileUpload.Has File)

{

fileUpload.Save As(Server.MapPa th(System.Confi guration.Config urationManager. AppSettings["picPaths"].ToString())
+ fileUpload.File Name);

SqlDataSource1. UpdateParameter s["pic"].DefaultValue = fileUpload.File Name;

}
.........

DetailsView datasource:

<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server" ConnectionStrin g="<%$
ConnectionStrin gs:ProdDb %>"

SelectCommand=" SELECT * FROM [Prod] WHERE [Id] = @Id "

WHERE [Id] = @Id "

UpdateCommand=
"

UPDATE [Prod] SET

[ProductName] = @ProductName,

[pic]= @pic,

WHERE [Id] = @Id


"


<<UpdateParamet ers>

<asp:Paramete r Name="CompanyNu mber" Type=int16 />

<asp:Paramete r Name="pic" Type="String" />

</UpdateParameter s>
<SelectParamete rs>

<asp:ControlPar ameter ControlID="Grid View1" Name="Id"

PropertyName="S electedValue" Type=int32 />

</SelectParameter s>

</asp:SqlDataSour ce>

Many thanks

JJ
Mar 30 '06 #3
The problem is that

UPDATE [Prod] SET

[ProductName] = @ProductName,

[pic]= @pic,

WHERE [Id] = @Id

will update [pic] to the value of @pic everytime, if you don't provide a
value for @pic then it will be set to null and so will your field.

Is the update event handler the updated event or the updating event?

Either way don't use

SqlDataSource1. UpdateParameter s["pic"].DefaultValue = fileUpload.File Name;

use e.NewValues["pic"] = fileUpload.File Name;

and make sure it is in the ItemUpdating event handler.

Then you need to make sure that pic gets uopdated to it's existing value by
having an else clause to your if (fileUpload.Has File) that says something
like

else
{
e.NewValues["pic"] = e.OldValues["pic"];
}

"jens Jensen" wrote:
<asp:TemplateFi eld HeaderText="Ima ge">

<itemtemplate >

<asp:Image ImageUrl='<%# Eval("pic", "../admin/images/{0}" ) %>'
runat="server" ID="image" />

</itemtemplate>

<EditItemTempla te>
<asp:FileUplo ad ID="fileUpload1 " runat="server" />

</EditItemTemplat e>

</asp:TemplateFie ld>
</Fields>

update event handler

.........

FileUpload fileUpload = ((DetailsView)s ender).FindCont rol("FileUpload 1") as
FileUpload;

if (fileUpload.Has File)

{

fileUpload.Save As(Server.MapPa th(System.Confi guration.Config urationManager. AppSettings["picPaths"].ToString())
+ fileUpload.File Name);

SqlDataSource1. UpdateParameter s["pic"].DefaultValue = fileUpload.File Name;

}
.........

DetailsView datasource:

<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server" ConnectionStrin g="<%$
ConnectionStrin gs:ProdDb %>"

SelectCommand=" SELECT * FROM [Prod] WHERE [Id] = @Id "

WHERE [Id] = @Id "

UpdateCommand=
"

UPDATE [Prod] SET

[ProductName] = @ProductName,

[pic]= @pic,

WHERE [Id] = @Id


"


<<UpdateParamet ers>

<asp:Paramete r Name="CompanyNu mber" Type=int16 />

<asp:Paramete r Name="pic" Type="String" />

</UpdateParameter s>
<SelectParamete rs>

<asp:ControlPar ameter ControlID="Grid View1" Name="Id"

PropertyName="S electedValue" Type=int32 />

</SelectParameter s>

</asp:SqlDataSour ce>

Many thanks

JJ

Mar 30 '06 #4
diesalher
1 New Member
Many thanks, that was useful for me too. There's not another place in wich this issue is explained better.

Soz for my English
Apr 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3619
by: Andrew Robinson | last post by:
Is there any way to accomplish two way data binding in a Details View with a DataSet or DataTable as the DataSource. All I want is to get an updated DataSet or DataTable back from the DetailsView and then handle my updating manually. -Andrew
12
8688
by: Jim Hammond | last post by:
I am passing the whole object instead or parameters in my select and update methods. I can get the updated object if I set UpdateMethod, let ASP.NET autogenerate an update button, and then press update after making changes, but I don't want that update button. How can I get the updated object when the user presses one of my other action buttons?
0
1262
by: Andre | last post by:
Hi, In my detailsview, when editing, i try to use a Filepload field to change the file name in my DB and upload it to the server. But when i click the Update button i receive this error : Must declare @image1 Every other field in my detailsview (textbox, checkbox, calendar) are working #1, but not this one...
4
7710
by: Kjell Arne | last post by:
Hi! I have a detailsview control in a webpart with some templated fields on. I set the ValidationGroup property to som value on these fields to distinguish from other web parts on the page. However, I'm not able to set the same ValidationGroup on the submit controls on the detailsview. Those linkbuttons(update, insert) are auto generated now. 1. Is it possible to set ValidationGroup on the detailsview? 2. How would I go about...
0
2882
by: Christian Schlemmer | last post by:
hi, in a DetailsView i have a image display. images i want to store in a seperate directory, but it a path is added to Bind update and delete is not working. just Bind makes my DetailsView updateable, but scripts and images would be nice to be seperated.
0
1354
by: sansie | last post by:
Hi, I have a page which is basically a details view(in inset mode) inside a datalist. The problem is I want to set the field "invoiceID" (of the detailsview) to an invoiceID coming through the query string of the page. Now, I have sucessfully done this with a detailsview that is not enclosed in a datalist, using the following page load script: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
1
4137
by: ledneh | last post by:
I've been working on concurrency checking for an application I'm building, and a minor part of it has me slightly stumped. I've got a DetailsView that populates from an ObjectDataSource, using business objects with optimistic concurrency checking built in in my Save() method (against a timestamp column). This can be proven to work perfectly in the following scenario: - Start app, go to the DetailsView page (defaults to readonly), open a...
0
1083
by: info | last post by:
Hi guys. I have been thrown into the deep end. I don't know ASP, and with my C# development, I haven't used data aware controls. I am swimming OK so far (Image uploaded completed, XML/XSL menu created for the Master Page) but now now I have been asked to create a
5
3451
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration: default.aspx:
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.