如何在GridView中设置LinkBut​​ton的可见性 [英] How to set the visibility of a LinkButton in a GridView

查看:67
本文介绍了如何在GridView中设置LinkBut​​ton的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有一个绑定到SqlDataSource的GridView,并且想尝试根据该行中列的值来设置LinkBut​​ton的可见性,例如:

如果ACTION_STATUS列为12(关闭),那么我想隐藏LinkBut​​ton,我知道我应该能够使用LinkBut​​ton.Visible = false;.为此,但不确定如何检查ACTION_STATUS的值

我也希望能够在页面后面的代码中处理所有这一切.

一如既往,任何帮助将不胜感激.

谢谢

Pete

Hello

I have a GridView bound to a SqlDataSource and would like to try and set the visibility of a LinkButton based on the value of column in that row for example:

If Column ACTION_STATUS is 12 (Closed) then I want to hide the LinkButton I know I should be able to use the LinkButton.Visible = false; to do this, but not sure how to check the value of ACTION_STATUS

I want to be able to handle all this in the code behind page too.

As ever any help would be most appreicated.

Thanks

Pete

推荐答案

嗨 这很简单,其中e.Row.Cells [ 0 ]是您的ACTION_STATUS索引 clumn
Hi it''s very simple where e.Row.Cells[0] is index of your ACTION_STATUS clumn
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if ((Convert.ToInt32(e.Row.Cells[0].ToString()) == 12))
            {
                HyperLink hy = (HyperLink)e.Row.FindControl("HyperLink");
                hy.Visible = false;
            }
        }




如有任何疑问,请让我知道.

如果有帮助,请提供"投票",如果这是正确的答案,请提供"接受答案".:rose:

谢谢,
Imdadhusen




Please do let me know, if you have any doubt.

Please provide "Vote" if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen




首先,您需要找到链接按钮在哪一列中.

然后,在找到之后,按如下方式提到行数据绑定事件中的单元格号.


Hi,

First you need to find the link button is there in which column.

Then after finding,mention that cell no in row databound event as follows.


protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if ((Convert.ToInt32(e.Row.Cells[0].ToString()) == 12))
            {
                HyperLink hy = (HyperLink)e.Row.FindControl("HyperLink");
                hy.Visible = false;
            }
        }


如果仍然出错,请检查链接按钮单元格的索引位置代码或调用Gridview的行数据绑定事件的代码.


If you are still getting error, please check code for index position of linkbutton cell or where you are calling row databound event of Gridview.


Gridview_RowDataBound(..)
{
if(e.Row.cell ["ACTION_STATUS"].Text == 12)
{
(((LinkBut​​ton)e.Row.FindControl(& quot; LinkBut​​toVisible = false;
}
}
Gridview_RowDataBound(..)
{
if( e.Row.cell["ACTION_STATUS"].Text == 12)
{
((LinkButton)e.Row.FindControl("LinkButtoVisible = false;
}
}


这篇关于如何在GridView中设置LinkBut​​ton的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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