如何动态显示图像

如何动态显示图像

本文介绍了如何动态显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!
我对ASP.NET数据绑定有疑问.我正在创建一个网站,
显示某些艺术家的新闻...主页 News.aspx 包含按日期降序排列的新闻的整个列表....
并且每个新闻条目都有一个 Read More html链接,该链接指向
ViewNews.aspx?id = {id} 页,而不是新闻ID通过查询字符串传递..
ViewNews.aspx 页显示有关艺术家...的扩展信息.
有些新闻有照片,有些没有....
我有一个SQL Server表

Hi guys!
I have a question about ASP.NET data binding. I''m creating a site that
displays news for some artist...the main page News.aspx contains the whole list of news ordered by date descending....
and each news item has a Read More html link that points to a
ViewNews.aspx?id={id} page than a news id is passed through a query string..
The ViewNews.aspx page displays EXTENDED info about artist....
some news items have photos some don''t....
I have an SQL Server table

 CREATE TABLE News(
  [News ID] uniqueidentifier PRIMARY KEY NOT NULL DEFAULT NEWID(),
  [Title] nvarchar(500) NOT NULL,
  [Digest] nvarchar(3000) NOT NULL, // short info
  [Content] ntext NOT NULL, // extended info
  [PhotoLink] varchar(100) NULL // for saving image path on server
);



关键是...我想正确地完整显示我的新闻...
如果新闻没有相关的图像,而我不需要将图像插入HTML,如果新闻有相关的图像,那么
它必须向左浮动,文本必须向右浮动
我这样做:



The point is that ...I want to fully show my news item correctly...
if a news item doesn''t have an associated image than I don''t need to insert image into HTML, if there is an associated image with that news item then
it must be floatted left and text must be floated right
I do this:

<asp:SqlDataSource ID = "srcNewsSolo" runat = "server"
        ConnectionString="<%$ ConnectionStrings:MusicDBConnString %>"

        SelectCommand="SELECT [Title], [Content], [PhotoLink] FROM [News] WHERE ([News ID] = @News_ID)">
     <SelectParameters>
         <asp:QueryStringParameter Name="News_ID" QueryStringField="id"   />
     </SelectParameters>


<asp:DataList id = "soloNewsItem" DataSourceID = "srcNewsSolo" runat = "server>
<itemtemplate>
<span style="color: Orange;"><%# Eval("Title") %> </span>

<% if ( Eval("PhotoLink") != null) { %>
  <img src = "<%# Eval("PhotoLink") %>" style = "float: left; " />
<% } %>

<span style="color: White"> <%# Eval("Content") %> </span>

</itemtemplate>



我在这里有一些错误...如何解决它们???如何使用Container.DataItem ???
我没有Intellisense !!!!!!!如何动态决定是否渲染照片....请帮助!!!!! !!!!!!!!!!!!!!!!!!!!!



I have some errors here ...how to fix them??? how to use Container.DataItem???
I don''t have in Intellisense!!!!!!! How to dynamically decide whether to render photo or not .... Please help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

推荐答案



我在这里有一些错误...如何解决它们???如何使用Container.DataItem ???
我没有Intellisense !!!!!!!如何动态决定是否渲染照片....请帮助!!!!! !!!!!!!!!!!!!!!!!!!!!



I have some errors here ...how to fix them??? how to use Container.DataItem???
I don''t have in Intellisense!!!!!!! How to dynamically decide whether to render photo or not .... Please help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


<img src = ''<%# Eval("PhotoLink") %>'' style = ''float:left; visibility:<%# String.IsNullOrEmpty(Eval("PhotoLink").ToString())?"hidden":"visible" %>'' />



这篇关于如何动态显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 13:21