|
|
 |
| General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums. If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category.
** PLEASE BE SPECIFIC WITH YOUR QUESTION **
When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the General .NET section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |
|

August 6th, 2007, 01:09 PM
|
|
Registered User
|
|
Join Date: Aug 2007
Location: Jaipur, , India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
fileupload control in formview insert item templat
hi Friends..
I am new to asp.net2.o world & trying my hands here & there,
when trying i find utility of using server controls in formview
very useful.now the problem is this that when i tried to use
fileupload control in formview insert item template, that is
not working, i am trying to upload a image file in my data folder
as well as in data table. my data type for images is varchar.
i have tried it lot in net but no success plz help me,if u
can give me full code or method of solving my problem
thank you friends
|

August 6th, 2007, 01:20 PM
|
|
Friend of Wrox
|
|
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
First of all, datatype of image cannot be varchar. I think it should be image. Or, you can store the path of image file in database table. For uploading the file in some folder on server, use following code:
FileUpload1.PostedFile.SaveAs("C:\\FolderName"); // you should preferably use relative path here
|

August 6th, 2007, 01:43 PM
|
|
Registered User
|
|
Join Date: Aug 2007
Location: Jaipur, , India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi gaurav,
first of all thanks to reply.
i have made a database table in sql where with other string
items like name address etc, i have used a varchar datatype
for my images & store data in jpg format like abc.jpg
now when i am using a formview to see data in item template
i dragged a imageweb control in formview & binded it to
image(varchar) field of my database it is working fine
up to this point ,but now in inseritem template i am using
a file uploader control to upload file the only binding properties
it is showing is enable & visible. , thatswhy i am not able
to bind the file upload control to image field.i have not used
any code for file uploader
if you think that this method is wrong can you tell me another method
to do it i know that i am asking too much but i would greatfull
to you.if u tell me preferably in c#
thankyou
|

August 6th, 2007, 01:55 PM
|
|
Registered User
|
|
Join Date: Aug 2007
Location: Jaipur, , India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi imar
now the link which u have given is fine with fileuploader
outside the formview , but would it work in inserttemplate
of form also & if yes than how & what i should write at
my form page
|

August 6th, 2007, 02:06 PM
|
|
Registered User
|
|
Join Date: Aug 2007
Location: Jaipur, , India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
my code in html page is like this & no C# code
<asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataKeyNames="Code"
DataSourceID="SqlDataSource1" Style="z-index: 100; left: 32px; position: absolute;
top: 88px" Height="368px" Width="560px" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" GridLines="Both" OnItemInserted="FormView1_ItemInserted" OnItemUpdated="FormView1_ItemUpdated" OnItemDeleted="FormView1_ItemDeleted">
<EditItemTemplate>
<h1>
<span style="font-size: 16pt">Edit Item.....</span></h1>
Code:
<asp:Label ID="CodeLabel1" runat="server" Text='<%# Eval("Code") %>'></asp:Label><br />
<br />
Name: <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>'>
</asp:TextBox><br />
<br />
Price: <asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>'>
</asp:TextBox><br />
<br />
Description: <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'>
</asp:TextBox><br />
<br />
FileThumb:
<asp:TextBox ID="TextBox1" runat="server" Style="z-index: 100; left: 120px; position: absolute;
top: 264px" Text='<%# Bind("FileThumb") %>'></asp:TextBox>
<br />
<br />
FileZoom:
<asp:TextBox ID="TextBox2" runat="server" Style="z-index: 101; left: 120px; position: absolute;
top: 304px" Text='<%# Bind("FileZoom") %>'></asp:TextBox>
<br />
<asp:Image ID="Image2" runat="server" ImageUrl='<%# Eval("FileThumb", "Images/ChildrenImages/Thumbs/{0}") %>'
Style="z-index: 103; left: 416px; position: absolute; top: 136px" />
<br />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
<h1>
<span style="font-size: 16pt">Insert Item....</span></h1>
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>'>
</asp:TextBox><br />
<br />
Price: <asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>'>
</asp:TextBox><br />
<br />
Description: <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'>
</asp:TextBox><br />
<br />
FileThumb:
<asp:FileUpload ID="FileUpload1" runat="server" Style="z-index: 100; left: 104px;
position: absolute; top: 240px" Enabled="true" Visible='<%# Eval("FileThumb") %>' />
<br />
<br />
FileZoom:
<asp:TextBox ID="FileZoomTextBox" runat="server" Text='<%# Bind("FileZoom") %>'>
</asp:TextBox><br />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
<h1>
<span style="font-size: 16pt">Product Description.......</span></h1>
Code:
<asp:Label ID="CodeLabel" runat="server" Text='<%# Eval("Code") %>'></asp:Label><br />
<br />
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>'></asp:Label><br />
<br />
Price:
<asp:Label ID="PriceLabel" runat="server" Text='<%# Bind("Price") %>'></asp:Label><br />
<br />
Description:
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Bind("Description") %>'>
</asp:Label><br />
<br />
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("FileThumb", "Images/ChildrenImages/Thumbs/{0}") %>'
Style="z-index: 100; left: 352px; position: absolute; top: 112px" />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit">
</asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
Text="Delete">
</asp:LinkButton>
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
Text="New">
</asp:LinkButton>
</ItemTemplate>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:FormView>
|

August 6th, 2007, 02:23 PM
|
 |
Wrox Author
Points: 33,554, Level: 80 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
|
|
Hi rakuntal,
My article mainly helps you with writing the code for saving and retrieving files from the database.
To mix those concepts with controls like the FormView, you need to look into some basic Data Control Tutorials:
http://quickstarts.asp.net/QuickStar...a/default.aspx
http://msdn2.microsoft.com/en-us/lib...inserting.aspx
In particular, search Google for more information about handling the ItemInserting and ItemUpdating events. Inside these events, you can use FindControl to find the file upload control and work from there.
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|

August 6th, 2007, 02:28 PM
|
|
Friend of Wrox
|
|
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have not worked with FormView. But can give you the idea. Add commandArgument=<%# Bind('DataTableID') %> to linkbutton "InsertButton". when this button is clicked and file for that corresponding row is browsed, write this code in FormView1_ItemInserting(not FormView1_ItemInserted):
string arg = e.CommandArgument.ToString();
// arg will contain the Id from the database for corresponding row
if (FileUpload1.PostedFile != null)
{
FileUpload1.Postedfile.saveAs("FilePath");
// or if you want to save the file in database, write code here
// insert the data in the row with Id equal to e.CommandArgument.ToString() in database
}
|

August 6th, 2007, 02:30 PM
|
|
Friend of Wrox
|
|
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar, your previous article for saving and retrieving files from the database was great.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |