473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 <edititemtemplate> 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 6297
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 <edititemtemplate> 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:TemplateField HeaderText="Image">

<itemtemplate>

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

</itemtemplate>

<EditItemTemplate>
<asp:FileUpload ID="fileUpload1" runat="server" />

</EditItemTemplate>

</asp:TemplateField>
</Fields>

update event handler

.........

FileUpload fileUpload = ((DetailsView)sender).FindControl("FileUpload1") as
FileUpload;

if (fileUpload.HasFile)

{

fileUpload.SaveAs(Server.MapPath(System.Configurat ion.ConfigurationManager.AppSettings["picPaths"].ToString())
+ fileUpload.FileName);

SqlDataSource1.UpdateParameters["pic"].DefaultValue = fileUpload.FileName;

}
.........

DetailsView datasource:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:ProdDb %>"

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

WHERE [Id] = @Id "

UpdateCommand=
"

UPDATE [Prod] SET

[ProductName] = @ProductName,

[pic]= @pic,

WHERE [Id] = @Id


"


<<UpdateParameters>

<asp:Parameter Name="CompanyNumber" Type=int16 />

<asp:Parameter Name="pic" Type="String" />

</UpdateParameters>
<SelectParameters>

<asp:ControlParameter ControlID="GridView1" Name="Id"

PropertyName="SelectedValue" Type=int32 />

</SelectParameters>

</asp:SqlDataSource>

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.UpdateParameters["pic"].DefaultValue = fileUpload.FileName;

use e.NewValues["pic"] = fileUpload.FileName;

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.HasFile) that says something
like

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

"jens Jensen" wrote:
<asp:TemplateField HeaderText="Image">

<itemtemplate>

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

</itemtemplate>

<EditItemTemplate>
<asp:FileUpload ID="fileUpload1" runat="server" />

</EditItemTemplate>

</asp:TemplateField>
</Fields>

update event handler

.........

FileUpload fileUpload = ((DetailsView)sender).FindControl("FileUpload1") as
FileUpload;

if (fileUpload.HasFile)

{

fileUpload.SaveAs(Server.MapPath(System.Configurat ion.ConfigurationManager.AppSettings["picPaths"].ToString())
+ fileUpload.FileName);

SqlDataSource1.UpdateParameters["pic"].DefaultValue = fileUpload.FileName;

}
.........

DetailsView datasource:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:ProdDb %>"

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

WHERE [Id] = @Id "

UpdateCommand=
"

UPDATE [Prod] SET

[ProductName] = @ProductName,

[pic]= @pic,

WHERE [Id] = @Id


"


<<UpdateParameters>

<asp:Parameter Name="CompanyNumber" Type=int16 />

<asp:Parameter Name="pic" Type="String" />

</UpdateParameters>
<SelectParameters>

<asp:ControlParameter ControlID="GridView1" Name="Id"

PropertyName="SelectedValue" Type=int32 />

</SelectParameters>

</asp:SqlDataSource>

Many thanks

JJ

Mar 30 '06 #4
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
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...
12
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...
0
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...
4
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....
0
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...
0
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...
1
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...
0
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...
5
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:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.