如何根据加载将按钮更改为图像按钮? [英] How to change the button to image button based on loading ?

查看:76
本文介绍了如何根据加载将按钮更改为图像按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Repeater绑定转发器内的数据表我想使用基于数据表中一列的两个按钮方式



如果列有值使用'N'asp按钮是另一个值即将使用图像按钮怎么做。

I have use Repeater to bind the data table inside the repeater i want to use two button means based on one column in data table

if the column have value 'N' asp button is used is another value is coming use image button how to do it.

<% if ((Session["REVIEW_IND"].ToString() == "N"))
                                       { %>
<asp:Button ID="Review" runat="server" Text="REVIEW" OnClick="Review_click" ToolTip="Review" />
                                <%}
else if (Session["REVIEW_IND"].ToString() == "N")
                                       { %>
<asp:ImageButton ID="Review1" runat="server" Text="REVIEW" />
                                <% }  %></td>





什么我试过了:





What I have tried:

<% if ((Session["REVIEW_IND"].ToString() == "N"))
                                       { %>
<asp:Button ID="Review" runat="server" Text="REVIEW" OnClick="Review_click" ToolTip="Review" />
                                <%}
else if (Session["REVIEW_IND"].ToString() == "N")
                                       { %>
<asp:ImageButton ID="Review1" runat="server" Text="REVIEW" />
                                <% }  %></td>

推荐答案

如果你想要要从数据源中读取值,您需要从数据源中读取它。您的代码正在尝试从会话中读取值,该会话与数据源无关。



在ASP.NET中探索会话 [ ^ ]



两个你的如果否则如果分支具有相同的测试。如果值为N,则会显示该按钮。如果该值是其他任何值,则不显示



此外, ImageButton 控件 [< a href =https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.imagebutton(v=vs.110).aspx\"target =_ blanktitle =New Window > ^ ]没有公共文本属性,因此您当前的标记将无效。



如果要根据条件显示多组内容中的一组,最简单的选择可能是使用 MultiView 控件 [ ^ ]:

If you want to read a value from the data source, then you need to read it from the data source. Your code is trying to read the value from the session, which has no connection to the data source.

Exploring Session in ASP.NET[^]

Both your if and else if branches have the same test. If the value is "N", the button will be shown. If the value is anything else, nothing will be shown.

Also, the ImageButton control[^] doesn't have a public Text property, so your current markup won't work.

When you want to display one of multiple sets of content depending on a condition, the simplest choice is probably to use the MultiView control[^]:
<asp:MultiView runat="server" 
    ActiveViewIndex='<%# Eval("REVIEW_IND", "{0}") == "N" ? 0 :1 %>'
>
<asp:View runat="server">
    <asp:Button ID="Review" runat="server" 
        Text="REVIEW" 
        ToolTip="Review" 
        OnClick="Review_click" 
    />
</asp:View>
<asp:View runat="server">
    <asp:ImageButton ID="Review1" runat="server" 
        ImageUrl="..." 
        AlternateText="REVIEW" 
    />
</asp:View>
</asp:MultiView>


这篇关于如何根据加载将按钮更改为图像按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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