Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 26, 2012 04:39 AM by Coolbudy
Member
50 Points
337 Posts
Nov 24, 2012 12:23 PM|LINK
hey guys,
I want to update image using detailsview but i facing problem my code is mention below
protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e) { FileUpload filename = (FileUpload)((DetailsView)sender).FindControl("fileupload");
filename.SaveAs(Server.MapPath("Images/" + filename));
objclass.Image = "Images/" + filename;
objclass.Update()
}
here .aspx code
<asp:DetailsView ID="DetailsView1" DataKeyNames="Uid" runat="server" AutoGenerateRows="False" Height="50px" Width="125px" OnItemCommand="DetailsView1_ItemCommand" BorderWidth="0" CellPadding="0" CellSpacing="7" GridLines="None" OnItemUpdating="DetailsView1_ItemUpdating"> <Fields> <asp:TemplateField> <ItemTemplate> <asp:FileUpload ID="fileupload" runat="server" /> </ItemTemplate> <EditItemTemplate> <asp:FileUpload ID="fileupload" runat="server" /> </EditItemTemplate> </asp:TemplateField>
</Fields> </asp:DetailsView>
but i did'nt get image path where is i'm wrong?
All-Star
118619 Points
18779 Posts
Nov 25, 2012 01:56 AM|LINK
Hi,
I'm afraid you should find the specific item for the detailsview and then call FindControl,please have a try like this:
void dv_ItemUpdating(object sender, DetailsViewUpdateEventArgs e) { FileUpload filename = (FileUpload)((DetailsView)sender).Rows[0].FindControl("Your Id Here") filename.SaveAs(Server.MapPath("Images/" + filename)); objclass.Image = "Images/" + filename; objclass.Update() }
Nov 26, 2012 04:17 AM|LINK
hey budy i try your code but its no treturn path how can i got the path?
Nov 26, 2012 04:26 AM|LINK
Coolbudy hey budy i try your code but its no treturn path how can i got the path?
Hello again,
You can use FileUpLoad's property——PostedFile.FileName.
Or directly use FileName.
But to be honest——You should know that you don't care about the path because you wanna save them to Server, and the paths are clients'.
Nov 26, 2012 04:31 AM|LINK
its alll about done because i never use detailsview before so please guide me i write my code below which not return path
FileUpload filename1 = (FileUpload)((DetailsView)sender).Rows[0].FindControl("fileupload"); filename1.SaveAs(Server.MapPath("Images/" + filename1)); objclass.Image = "Images/" + filename1;
Nov 26, 2012 04:34 AM|LINK
Coolbudy i write my code below which not return path
What does this mean?
I think a FileUpLoad will carry your file there, and you can just call it:
filename1.SaveAs(Server.MapPath("Images/" + filename1.FileName));
Nov 26, 2012 04:39 AM|LINK
hey its solve by your code thank u so much...............................
Coolbudy
Member
50 Points
337 Posts
Problem in Detailsview ImageUpload
Nov 24, 2012 12:23 PM|LINK
hey guys,
I want to update image using detailsview but i facing problem my code is mention below
protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
FileUpload filename = (FileUpload)((DetailsView)sender).FindControl("fileupload");
filename.SaveAs(Server.MapPath("Images/" + filename));
objclass.Image = "Images/" + filename;
objclass.Update()
}
here .aspx code
<asp:DetailsView ID="DetailsView1" DataKeyNames="Uid" runat="server" AutoGenerateRows="False"
Height="50px" Width="125px" OnItemCommand="DetailsView1_ItemCommand"
BorderWidth="0" CellPadding="0" CellSpacing="7" GridLines="None" OnItemUpdating="DetailsView1_ItemUpdating">
<Fields>
<asp:TemplateField>
<ItemTemplate>
<asp:FileUpload ID="fileupload" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:FileUpload ID="fileupload" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
but i did'nt get image path where is i'm wrong?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Problem in Detailsview ImageUpload
Nov 25, 2012 01:56 AM|LINK
Hi,
I'm afraid you should find the specific item for the detailsview and then call FindControl,please have a try like this:
void dv_ItemUpdating(object sender, DetailsViewUpdateEventArgs e) { FileUpload filename = (FileUpload)((DetailsView)sender).Rows[0].FindControl("Your Id Here") filename.SaveAs(Server.MapPath("Images/" + filename)); objclass.Image = "Images/" + filename; objclass.Update() }Coolbudy
Member
50 Points
337 Posts
Re: Problem in Detailsview ImageUpload
Nov 26, 2012 04:17 AM|LINK
hey budy i try your code but its no treturn path how can i got the path?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Problem in Detailsview ImageUpload
Nov 26, 2012 04:26 AM|LINK
Hello again,
You can use FileUpLoad's property——PostedFile.FileName.
Or directly use FileName.
But to be honest——You should know that you don't care about the path because you wanna save them to Server, and the paths are clients'.
Coolbudy
Member
50 Points
337 Posts
Re: Problem in Detailsview ImageUpload
Nov 26, 2012 04:31 AM|LINK
its alll about done because i never use detailsview before so please guide me i write my code below which not return path
FileUpload filename1 = (FileUpload)((DetailsView)sender).Rows[0].FindControl("fileupload");
filename1.SaveAs(Server.MapPath("Images/" + filename1));
objclass.Image = "Images/" + filename1;
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Problem in Detailsview ImageUpload
Nov 26, 2012 04:34 AM|LINK
What does this mean?
I think a FileUpLoad will carry your file there, and you can just call it:
filename1.SaveAs(Server.MapPath("Images/" + filename1.FileName));
Coolbudy
Member
50 Points
337 Posts
Re: Problem in Detailsview ImageUpload
Nov 26, 2012 04:39 AM|LINK
hey its solve by your code thank u so much...............................