博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在asp.net中,添加itemtempert 项模板时,如果在项模板里有其它控件,如何控件这些控件的属性?...
阅读量:7105 次
发布时间:2019-06-28

本文共 1378 字,大约阅读时间需要 4 分钟。

举个例子

 
 
 
 1 
<
form id
=
"
form1
"
 runat
=
"
server
"
>
 2 
    
<
div
>
 3 
        
<
asp:LinkButton Text
=
"
上一级目录
"
 runat
=
"
server
"
 ID
=
"
preButton
"
 
/>
 4 
        
<
br
/>
 5 
 6 
        
 7 
        
<
asp:Repeater ID
=
"
Repeater1
"
 runat
=
"
server
"
 
 8 
            onitemcommand
=
"
Repeater1_ItemCommand
"
 onitemdatabound
=
"
Repeater1_ItemDataBound
"
 
 9 
            
>
10 
        
<
ItemTemplate
>
11 
        
<%
#Eval(
"
ID
"
%>
.
12 
        
<
a href
=
"
<%#Eval(
"
filepath
"
) %>
"
><%
#Eval(
"
fileName
"
%></
a
>
13 
14 
            
<
asp:Button runat
=
"
server
"
 ID
=
"
Button1
"
 Text
=
"
"
 CommandName
=
"
deletebtn
"
 CommandArgument
=
'
<%#Eval("fileName") %>
'
/>
15 
            
<
br
/>
16 
        
</
ItemTemplate
>
17 
18 
19 
20 
        
</
asp:Repeater
>
21 
    
22 
    
</
div
>
23 
    
</
form
>

 

如果 要将这里的 button1 设置为 隐藏属性

 

刚可以这样做

 

 

 1 
    
protected
 
void
 Repeater1_ItemDataBound(
object
 sender, RepeaterItemEventArgs e)
 2 
    {
 3 
        
if
 (e.Item.ItemType 
==
 ListItemType.Item 
||
 e.Item.ItemType 
==
 ListItemType.AlternatingItem)
 4 
        {
 5 
             
string
 ss 
=
 Session[
"
User
"
].ToString();
 6 
 7 
            
if
 (ss 
==
 
"
Admin
"
)
 8 
            {
 9 
                ((Button)e.Item.FindControl(
"
Button1
"
)).Visible 
=
 
true
;
10 
            } 
else
11 
            {
12 
            ((Button)e.Item.FindControl(
"
Button1
"
)).Visible 
=
 
false
;
13 
            }
14 
        }
15 
    }
16 
}

 

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)

这一句是用来判断 是不是属于项模板的内容。

((Button)e.Item.FindControl("Button1")).Visible = true;

用来对对象做出判断。

 

其它控件也是类似的。

 

 

 

 

转载于:https://www.cnblogs.com/lujin49/archive/2011/07/22/2113413.html

你可能感兴趣的文章
PAT 1067 Sort with Swap[难]
查看>>
指针,为何不能在全局作用域内申请内存?
查看>>
Xilinx器件原语
查看>>
jquery的使用 超级快速入门 熟练使用
查看>>
如何在Windows Server 2008 R2下搭建FTP服务
查看>>
人才市场的IT职位分析
查看>>
ETL,你的系统可以吗?
查看>>
如何选择正确的产品路线图
查看>>
VIM7.3中文手册
查看>>
Python文件夹与文件的操作
查看>>
Deep learning:四十八(Contractive AutoEncoder简单理解)
查看>>
NSDate和NSString相互转换 (转)
查看>>
ASCII Unicode UTF-8 之间的关系
查看>>
计算四则运算表达式(Java语言实现)
查看>>
5、反射-动态代理
查看>>
C++中的类型转换
查看>>
Linux内核的冷热缓存
查看>>
Rop攻击
查看>>
USACO习题:Palindromic Squares
查看>>
C语言中有bool类型吗?
查看>>