根据其他值显示图像 [英] Display image based on another value

查看:58
本文介绍了根据其他值显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据另一个模板字段值显示图像。



示例人数(0010200)和保存在文件夹中的图像是00102000.jpg,如果是人数( 01234)和保存在文件夹中的图像是01234.jpg等像这样我有很多员工图像。这全部保存在/ img / webfolder。



现在当永远lable2人数更改我需要更改image1,这将与人数相同,



请建议我实现相同。示例代码如下。



我尝试过:



I want to display image based on another templatefield value.

Example person num(0010200) and image saved in folder is 00102000.jpg , if person num(01234) and image saved in folder is 01234.jpg, etc. like this i have many employee images.and this all saved in /img/ webfolder.

Now when ever lable2 person num changes i need to change the image1 which will be same as person num,

please suggest me to achieve the same. example code below.

What I have tried:

<asp:TemplateField HeaderText="person_num" SortExpression="person_num">
<asp:BoundField DataField="full_name" HeaderText="full_name" SortExpression="full_name" />
<asp:TemplateField HeaderText="Image">

推荐答案

首先,我认为你想拥有你在问题中提出的场景中的一个小变化,即

First of all, I consider you want to have a small change in the scenario you have presented in the question i.e,
Quote:

示例人数(0010200)保存在文件夹中的图像是00102000.jpg,如果人数(01234)和保存在文件夹中的图像是01234.jpg

Example person num(0010200) and image saved in folder is 00102000.jpg , if person num(01234) and image saved in folder is 01234.jpg



它应该是

- - person_num = 0010200 then image = 0010200.jpg (注意:最后2个零而不是3,如问题所述,认为这是一个错字)

person_num = 01234 then image = 01234.jpg

- person_num = 0010200 then image = 00102000.jpg (注意:最后加1个零,与问题相同)

person_num = 01234 then image = 012340.jpg (最后加1个零)



第一种情况,如果您将图像保存为相同的na我作为person_num你可以使用以下代码而不添加任何其他逻辑。


It should be either
-- person_num = 0010200 then image = 0010200.jpg (note: 2 zeros at the end instead of 3 as stated in the question considering it to be a typo)
person_num = 01234 then image = 01234.jpg
-- person_num=0010200 then image = 00102000.jpg (note: 1 more zero added at the end, same as question)
person_num = 01234 then image = 012340.jpg (1 more zero added to at the end)

For the first case if you are saving the images as the same name as person_num you can use following code without any other logic added to it.

<itemtemplate headertext="Image">
     <img src="<%# Eval("person_num","~/Images/{0}.jpg") %>" <br="" mode="hold"> </itemtemplate>



第二种情况,你需要非常简单的改变,即


For the second case, you need just very simple change i.e,

<itemtemplate headertext="Image">
     <img src="<%# Eval("person_num","~/Images/{0}0.jpg") %>" <br="" mode="hold"> </itemtemplate>





如果你的要求是别的,请告诉我。

希望,它有帮助:)



Please let me know if your requirement is something else.
Hope, it helps :)


优秀......有些相同。我的结果几乎就是你的想法,



< asp:image id =Image2runat =serverimageurl =<%#string.Format ( 〜/ IMG / {0} .JPG,评估和演示( person_Num))%>中height =300width =300>
Excellent...some what same. and i got the result almost your idea,

<asp:image id="Image2" runat="server" imageurl="<%# string.Format("~/img/{0}.jpg",Eval("person_Num"))%>" height="300" width="300">


这篇关于根据其他值显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆