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>
2 个解决方案
#1
2
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;
}
}
#2
0
I suggest pass the image name as parameter to GetImagePath Try this:
我建议将图像名称作为参数传递给GetImagePath试试这个:
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".
VirtualPathUtility.ToAbsolute(string)将虚拟路径转换为应用程序绝对路径。所以你会得到类似“/images/yourimage.jpg”的东西。
#1
2
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;
}
}
#2
0
I suggest pass the image name as parameter to GetImagePath Try this:
我建议将图像名称作为参数传递给GetImagePath试试这个:
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".
VirtualPathUtility.ToAbsolute(string)将虚拟路径转换为应用程序绝对路径。所以你会得到类似“/images/yourimage.jpg”的东西。