[英]Image Button does not hide on page load
我使用下面的代码在页面加载时隐藏了模板字段Imagebutton,但是它不起作用,请提前感谢:
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim ImageButton1 As ImageButton = DirectCast(GridView1.FindControl("ImageButton1"), ImageButton)
If User.Identity.Name.Substring(InStr(User.Identity.Name, "\")).ToUpper = "User1" Then
ImageButton1.Visible = False
End If
End Sub
假设您binding grid before and it has rows
有binding grid before and it has rows
。 在网格的某些行中找到ImageButton,而不是在gridview中找到 。 if
您要比较的if
条件似乎永远不会成立,因为您正在将ToUpper之后的字符串与非大写的字符串进行比较,请在使用ToUpper时将Change User1 to USER1
。
更改
Dim ImageButton1 As ImageButton = DirectCast(GridView1.FindControl("ImageButton1"), ImageButton)
If User.Identity.Name.Substring(InStr(User.Identity.Name, "\")).ToUpper = "User1" Then
ImageButton1.Visible = False
End If
至
Dim ImageButton1 As ImageButton = DirectCast(GridView1.Rows(0).FindControl("ImageButton1"), ImageButton)
If User.Identity.Name.Substring(InStr(User.Identity.Name, "\")).ToUpper = "USER1" Then
ImageButton1.Visible = False
End If
循环遍历整个网格
For Each row As GridViewRow In GridView1.Rows
Dim ImageButton1 As ImageButton = DirectCast(row.FindControl("ImageButton1"), ImageButton)
If User.Identity.Name.Substring(InStr(User.Identity.Name, "\")).ToUpper = "USER1" Then
ImageButton1.Visible = False
End If
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.