如何在asp,net图像控件中显示单个动态图像 [英] how to display single dynamic image in asp,net image control

查看:64
本文介绍了如何在asp,net图像控件中显示单个动态图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个母版页,在其中我采取了一个图像控制,在该控件中,我想根据内容页面显示数据库url中的单个图像.我在数据库imageurl和页面名中有两列.并且图像位于文件夹图像中.我不知道该怎么做,因为beauaus图像控件没有数据源属性.

i have one master page in which i have taken one image control in which i want to show single image from database url according to content page.. i have two columns in database imageurl and pagename. and images are in a folder images.. i have no idea how to do this becauese image control does not have data source property.

推荐答案

在代码中,您必须从数据库中获取图像URL并将其分配给Image控件的ImageUrl属性.
In code, you have to fetch the image URL from the database and assign it to the ImageUrl property of the Image control.


图像控件没有数据源属性.
但是,图像确实具有源"属性.

步骤:
1.从数据库中,根据路径查询图像路径.查询可能是这样的:
image control does not have data source property.
But, image does have a ''source'' property.

Steps:
1. From database, query the image path based on the path. Query could be like:
SELECT imageURL FROM myTable WHERE pagename=@currentContentPage


2.根据返回的imageURL,您需要对其进行访问,然后将其用作图像源.像这样的东西:


2. Based on the imageURL returned, you need to access it and then use this as a image source. Something like:

myImage.ImageUrl = dataTableFetched.Tables[0].Rows[0][imageURL].ToString();
//if it was absolute path to the server folder then it will work 
//or else first you need to format iinto correct url and then assign to imageURL



您需要检查验证,并根据需要将其为null.

试试吧!



You need to check for validations and null as per need.

Try!


这篇关于如何在asp,net图像控件中显示单个动态图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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