如果在您的查询中获得JPG文件的文件名,您可以在ASP页面上添加类似于您的GridView的<Columns> </Columns>
标记的东西。
<asp:ImageField DataImageUrlField="YourJPGFileNameColumn"
DataImageUrlFormatString="~\YourPathWhereTheImageIs\{0}.jpg" >
<ControlStyle Width="100px" />
</asp:ImageField>
的“YourJPGFileNameColumn”必须对您的查询和{0}中您的查询返回的值将是列名的回报。
例如,如果您的查询返回的表是这样的:
| ProductID |
-----------
| 1234 |
| 010102 |
| 5678 |
你会写你这样的代码:
<asp:ImageField DataImageUrlField="ProductID"
DataImageUrlFormatString="~\YourPathWhereTheImageIs\{0}.jpg" >
<ControlStyle Width="100px" />
</asp:ImageField>
问候。
嗨@Tombala 感谢您的帮助,这似乎正是我想要实现的。我遇到的问题是,我不想从sql查询中获取imageURLstring,我从中获取其他数据,但在其后添加它。我目前在这个阶段,但不知道如何将sTextString添加到我的列表然后传递给gridview。 – user2192142 2013-05-11 17:59:13
string sTextString =“”; foreach(WebApplication.Data.Results.Result result in lResults)) if(result。UserAnswer == result.CorrectAnswer) { sTextString =“..images/tick.png”;其他 { sTextString =“..images/cross.png”; } } c_gvResults.DataSource = lResults.ToArray(); c_gvResults.DataBind(); – user2192142 2013-05-11 17:59:47
@ user2192142你会做什么是使用IMG标记方法,并检查任何列中的值,你想检查一个内联if语句类似于[这篇文章](http://stackoverflow.com/questions/ 10811023/conditional-logic-for-gridview-item-template-using-mark-up-only)has。我用这个例子更新了代码。 – Tombala 2013-05-12 02:14:54