[英]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.