TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
shoham tal
NA
3
6.4k
DetailsView with FileUpload Control
Mar 27 2012 7:15 AM
hello friends
i need some help:
i have a form with detailsView controls bounded to an ObjectDataSource.
inside the detailsView i have some textBoxes, dropDownLists and FileUpload control.
now the ObjectDataSource has another class to handle the insert method.
without the fileUpload everting is ok, but when i try to insert the file upload to the InsertParameters of ObjectDataSource, its not working.
any help will be appreciated!
here is the code...
default.aspx:
<%--
Data
sources
--
%>
<asp:ObjectDataSource
runat
=
"server"
ID
=
"ObjectDataSource1"
TypeName
=
"ShopLogic"
SelectMethod
=
"SelectShop"
InsertMethod
=
"InsertNewShop"
>
<InsertParameters>
<asp:ControlParameter
ControlID
=
"FileUpload1"
Type
=
"Object"
/>
</InsertParameters>
</asp:ObjectDataSource>
<%--
Data
sources
--
%>
<%--
details view
--
%>
<asp:detailsview
id
=
"detailsview2"
datasourceid
=
"shopDataSource"
autogeneraterows
=
"false"
runat
=
"server"
DefaultMode
=
"Insert"
>
<fields>
<asp:TemplateField
HeaderText
=
"title"
>
<InsertItemTemplate>
<asp:DropDownList ID="ddlTitle" runat="server" DataSourceID="ShopTitleDataSource" DataTextField="title"
DataValueField="title" SelectedValue='
<%
# Bind("title")
%>' >
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:BoundField
DataField
=
"name"
HeaderText
=
"name"
/>
<asp:BoundField
DataField
=
"phone"
HeaderText
=
"phone"
/>
<asp:BoundField
DataField
=
"site"
HeaderText
=
"site"
/>
<asp:TemplateField
HeaderText
=
"segment"
>
<InsertItemTemplate>
<asp:DropDownList ID="ddlSegment" runat="server" DataSourceID="ShopSegmentDataSource" DataTextField="segment"
DataValueField="segment" SelectedValue='
<%
# Bind("segment")
%>' >
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField
HeaderText
=
"image"
>
<InsertItemTemplate>
<asp:FileUpload
ID
=
"FileUpload1"
runat
=
"server"
/>
</InsertItemTemplate>
</asp:TemplateField>
<asp:commandfield
ButtonType
=
"Image"
showinsertbutton
=
"true"
InsertImageUrl
=
"buttons/new.png"
ShowCancelButton
=
"false"
showheader
=
"true"
headertext
=
"???? ????"
/>
</fields>
</asp:detailsview>
<%--
details view
--
%>
AppCode/ShopLogic.cs:
public
void
InsertNewShop
(
string
title
,
string
name
,
string
phone
,
string
site
,
string
segment
,
object
FileUpload
)
{
FileUpload
FileUpload1
=
FileUpload
as
FileUpload
;
//upload picture
string
imagePath
=
"~/ShopsImages/"
+
DateTime
.
Now
.
ToString
(
"ddmmyy_hhmmss"
)
+
FileUpload1
.
FileName
;
string
fullPath
=
HostingEnvironment
.
MapPath
(
imagePath
);
FileUpload1
.
SaveAs
(
fullPath
);
//create shop object
shop newShop
=
new
shop
();
newShop
.
title
=
title
;
//...more code...
db
.
AddToshops
(
newShop
);
db
.
SaveChanges
();
}
Reply
Answers (
0
)
Listview data key
Session state in ASP.NET