Reputation: 87
i have image-button control in a grid view my customer need to enter a path of folder in another page i stored this path in database i need because customer store images in external hard cannot transfer image from hard disk to website images because it has a huge size
my image table contain image-name when user display grid-view i concatenate image-name from database and path from database also how can i do that
<asp:TemplateField HeaderText="photo">
<ItemTemplate >
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# GetImagePath()+Eval("ImageName") %>' Width="100px" Height="100px" Style="cursor: pointer" OnClientClick = "return LoadDiv(this.src);" />
</ItemTemplate>
</asp:TemplateField>
Upvotes: 0
Views: 6409
Reputation: 13129
I suggest pass the image name as parameter to GetImagePath Try this:
public string GetImagePath(string imageName)
{
return VirtualPathUtility.ToAbsolute("~/images/" + imageName);
}
VirtualPathUtility.ToAbsolute(string) converts a virtual path to an application absolute path. So you will get something like "/images/yourimage.jpg".
Upvotes: 0
Reputation: 176896
you need write down in you function like this
public string GetImage(string name)
{
string path = Path.Combine(Server.MapPath(("~/Admin/Images/" , name));
return path;
}
or
you can also do like this
void GrdVw_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
Image rowImage = (Image) e.Row.FindControl("currentDocFile");
rowImage.ImageUrl = whatever;
}
}
Upvotes: 2