如何根据变量的值在单元格中显示图像 [英] How do I display an image in a cell based on value of variable

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

问题描述

你好,
我是ASP.NET和C#的新手.我想知道是否有人可以帮助我确定如何基于变量在表的中间列的单元格中显示特定图像(警告,错误或成功).我认为这需要通过标记来完成,但无法通过我发现的一些文章和讨论来弄清楚.谢谢!

我的变量及其关联的值是...
epsServerState =(联机或脱机)
epsFtpState =(正在运行或已停止)
epsSpoolerState =(正在运行或已停止)
epsEpicState =(正在运行或已停止)


Hello,
I''m new to ASP.NET and C#. I was wondering if anyone would be able to help me in determining how I can display a certain image (alert, error, or success) in a cell of the middle column within a table based on a variable. I believe this would need to be done through markup, but have not been able to figure it out with some of the articles and discussion i''ve found. Thanks!

My variables and their associated values are...
epsServerState = (online or offline)
epsFtpState = (running or stopped)
epsSpoolerState = (running or stopped)
epsEpicState = (running or stopped)


<table style="font-size: medium; font-family: fixedsys;" title="EPS1" 

            class="table">
            <tr>
                <td class="title" 

                    

                    

                    style="font-weight: bolder; font-variant: small-caps; text-transform: capitalize; color: #000080; border-collapse: collapse; empty-cells: hide; caption-side: top; font-size: large;">
                    EPS</td>
                <td class="gfx" 

                    

                    

                    

                    style="font-weight: bolder; font-variant: small-caps; text-transform: capitalize; color: #000080; border-collapse: collapse; empty-cells: hide; caption-side: top; font-size: large;">
                     </td>
                <td>
                </td>
            </tr>
            <tr>
                <td class="headings" align="right">
                    Server Status:</td>
                <td class="gfx" align="right">
                    <img class="style28" src="Images/success.png" /></td>
                <td align="justify" class="results">
                    <asp:Label ID="epsServerLabel" runat="server" CssClass="results"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="headings" align="right">
                    FTP Service:</td>
                <td class="gfx" align="right">
                    <img class="style28" src="Images/error.png" /></td>
                <td align="justify" class="results">
                    <asp:Label ID="epsFtpLabel" runat="server" CssClass="results"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="headings" align="right">
                    Spooler Service:</td>
                <td class="gfx" align="right">
                    <img class="style28" src="Images/alert.png" /></td>
                <td align="justify" class="results">
                    <asp:Label ID="epsSpoolerLabel" runat="server" CssClass="results"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="headings" align="right">
                    Epic Service:</td>
                <td class="gfx" align="right">
                    <img class="style28" src="Images/success.png" /></td>
                <td align="justify" class="results">
                    <asp:Label ID="epsEpicLabel" runat="server" CssClass="results"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="headings" align="right">
                    Processing:</td>
                <td class="gfx" align="right">
                    <img class="style28" src="Images/error.png" /></td>
                <td align="justify" class="results">
                    <asp:Label ID="epsProcessingLabel" runat="server" CssClass="results"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="headings" align="right">
                    Last Processed:</td>
                <td class="gfx" align="right">
                    <img class="style28" src="Images/alert.png" /></td>
                <td align="justify" class="results">
                    <asp:Label ID="epsProcessedLabel" runat="server" CssClass="results"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="headings" align="right">
                    Last Failed:</td>
                <td class="gfx" align="right">
                    <img class="style28" src="Images/success.png" /></td>
                <td align="justify" class="results">
                    <asp:Label ID="epsFailedLabel" runat="server" CssClass="results"></asp:Label>
                </td>
            </tr>
        </table>

推荐答案

您只需要添加一个图像控件,然后设置其URL,最简单的方法是调用方法背后的代码以获取需要检查的参数,然后根据这些值返回正确的图像URL.

如果您使用img标签,您仍然可以使用调用后的代码来设置src.
You just need to add an image control, and then set it''s URL, the easiest way is to call a code behind method that gets the parameters that need checking, and then returns the correct image URL based on those values.

If you use an img tag, you can still set the src using a code behind call.


代替img标签,请使用图片控件
Instead of img tag use image control
<asp:image id="imgServerOnline" runat="server" alt="serverstatus" xmlns:asp="#unknown"></asp:image>


或者,如果您仍然想要img标签,请添加ID&将runat归因于img标签.将其src属性设置为来自codebehind的图片网址.

在服务器端的
后面的代码中 添加此代码


or if you still want img tag then add id & runat attribut to img tag. Set its src property to image url from codebehind.

On server side in code behind
add this code

Bool IsServerOnline;
//Code to set value to variable
if(IsServerOffline)
{
imgServerOnline.ImageUrl="Images/Online.png"
}
else
{
imgServerOnline.ImageUrl="Images/Offline.png"
}


感谢您的建议.我浏览了另一篇文章,并通过执行以下操作能够解决此问题.

Thanks for the suggestions. I ran across another article and was able to resolve this problem by doing the following.

string epsFtpState = shell.Runspace.SessionStateProxy.GetVariable("epsFtpState").ToString();

if (epsFtpState.Contains(epsFtpState, "Stopped")){
	Image epsFTPimg = new Image();
	epsFTPimg.ImageUrl = "~/Images/error.png";
	epsFtpStatusPlaceHolder.Controls.Add(epsFTPimg);
}
else {
	//other code
}


这篇关于如何根据变量的值在单元格中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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