根据GV中的另一个控件的值隐藏gridview中的按钮(VB.NET) [英] Hide a button in gridview based on a value of another control inside the GV (VB.NET)

查看:83
本文介绍了根据GV中的另一个控件的值隐藏gridview中的按钮(VB.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在尝试根据gridview中另一个控件的值隐藏gvResults(gridview)中的按钮。



两个控件都是templatefield。



Hello,
I'm trying to Hide a button inside gvResults (gridview) based on the value of another control inside the gridview.

both controls are templatefield.

Protected Sub gvResults_RowDataBound(sender As Object, e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then

            Dim SPass As String = TryCast(e.Row.FindControl("lblSharePass"), Label).Text
            Dim ShareButton As Button = TryCast(e.Row.FindControl("btnShare"), Button)

            If Not String.IsNullOrEmpty(SPass) Then
                ShareButton.Visible = False
            Else
                ShareButton.Visible = True
            End If
        End If

    End Sub





lblSharePass绑定到数据库中的列



lblSharePass is binded to a column in the database

<asp:Label ID="lblSharePass" runat="server" Text='<%#Bind("SharePass") %>'></asp:Label>





我似乎无法做对。如果lblSharePass包含值,则btnShare不应该是可见的..但是,我尝试指定像SPass =1234这样的值并且它可以工作..



有人可以请帮助。



我尝试了什么:



i尝试过没什么, ,vbnullstring但他们没有工作。我还在RowCreated中创建了相同的子,但结果不成功。



I can't seem to get it right. btnShare should not be visible if lblSharePass contains a value.. However, I tried to specify the value like SPass = "1234" and it works..

Can someone please help.

What I have tried:

i tried isnothing, "", vbnullstring but non of them works. I also created the same sub in RowCreated but with unsuccessful results.

推荐答案

您可以绑定可见属性标记,不使用 RowDataBound 事件:

You can bind the Visible property in the markup, without using the RowDataBound event:
<asp:Button ID="btnShare" runat="server" 

    Visible='<%# String.IsNullOrWhiteSpace(Eval("SharePass", "{0}")) %>'

    ...

/>



(使用 IsNullOrWhiteSpace 将处理值为仅包含空格字符的字符串的情况。这在HTML中看起来是空的,但是不会传递 IsNullOrEmpty ,并且不会等于空字符串。)


(Using IsNullOrWhiteSpace will handle cases where the value is a string that only contains whitespace characters. This would look empty in HTML, but would not pass IsNullOrEmpty, and would not be equal to an empty string.)


这篇关于根据GV中的另一个控件的值隐藏gridview中的按钮(VB.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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