Lnk按钮应该是可见的 [英] Lnk button should be visible

查看:100
本文介绍了Lnk按钮应该是可见的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的grigview如下





课程代码日期Startdate Enddate



Clickhere(链接按钮)ASM 5 2016年5月10日2016年5月10日

Clickhere(链接按钮)2016年5月12日2016年5月17日

Clickhere(链接按钮)5月21日2016年5月25日



我不想在gridview中使用第2行和第3行链接按钮,因为在gridview中

代码(第2列)秒和thrid行代码为空。



每当代码中为空时我不想要链接按钮。我想设置visble false。



我的代码如下Gridview行数据绑定



protected void gvRank_RowDataBound(object sender,GridViewRowEventArgs e)

{



if(e.Row.RowType == DataControlRowType.DataRow)

{



LinkBut​​ton lnk =(LinkBut​​ton)e.Row.FindControl(LinkBut​​ton2);

TextBox text = (TextBox)e.Row.FindControl(Code);



if(text == null&& lnk == null)

{

lnk.Visble = false;

}



else

{

lnk.Visible = True;

}

}

}





但是在gridview输出中,我得到如下



课程代码天数Startdate Enddate



ASM 5 05 May 2016年5月10日

2016年5月12日2016年5月17日

2016年5月21日2016年5月25日



当然列所有链接按钮都可见false。我只希望第二行和第三行链接按钮只能显示为假。



我尝试过:



我有grigview如下





课程代码日期Startdate Enddate



Clickhere(链接按钮)ASM 5 2016年5月10日2016年5月10日

Clickhere(链接按钮)2016年5月12日2016年5月17日

Clickhere (链接按钮)2016年5月21日2016年5月25日



我不想在gridview中使用第2行和第3行链接按钮,因为在gridview中

代码(第2列)第二行和第三行代码为空。



每当代码中为空时我不想要链接按钮。我想设置visble false。



我的代码如下Gridview行数据绑定



protected void gvRank_RowDataBound(object sender,GridViewRowEventArgs e)

{



if(e.Row.RowType == DataControlRowType.DataRow)

{



LinkBut​​ton lnk =(LinkBut​​ton)e.Row.FindControl(LinkBut​​ton2);

TextBox text = (TextBox)e.Row.FindControl(Code);



if(text == null&& lnk == null)

{

lnk.Visble = false;

}



else

{

lnk.Visible = True;

}

}

}





但是在gridview输出中,我得到如下



课程代码天数Startdate Enddate



ASM 5 05 May 2016年5月10日

2016年5月12日2016年5月17日

2016年5月21日2016年5月25日



当然列所有链接按钮都可见false。我只想要第二行和第三行链接按钮只能看到假。

I have grigview as follows


Course Code Days Startdate Enddate

Clickhere(Link Button) ASM 5 05 May 2016 10 May 2016
Clickhere(Link Button) 12 May 2016 17 May 2016
Clickhere(Link Button) 21 May 2016 25 May 2016

I dont want 2nd row and third row link button in gridview because in gridview
Code(2nd column) second and thrid row code is empty.

Whenever empty in Code i do not want link button. i want to set visble false.

for that my code as follows in Gridview row databound

protected void gvRank_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{

LinkButton lnk= (LinkButton)e.Row.FindControl("LinkButton2");
TextBox text = (TextBox)e.Row.FindControl("Code");

if (text == null && lnk == null)
{
lnk.Visble = false;
}

else
{
lnk.Visible = True;
}
}
}


But in gridview output i get as follows

Course Code Days Startdate Enddate

ASM 5 05 May 2016 10 May 2016
12 May 2016 17 May 2016
21 May 2016 25 May 2016

In course column all the link button are visible false. i want only the second row and third row link button only visible false.

What I have tried:

I have grigview as follows


Course Code Days Startdate Enddate

Clickhere(Link Button) ASM 5 05 May 2016 10 May 2016
Clickhere(Link Button) 12 May 2016 17 May 2016
Clickhere(Link Button) 21 May 2016 25 May 2016

I dont want 2nd row and third row link button in gridview because in gridview
Code(2nd column) second and thrid row code is empty.

Whenever empty in Code i do not want link button. i want to set visble false.

for that my code as follows in Gridview row databound

protected void gvRank_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{

LinkButton lnk= (LinkButton)e.Row.FindControl("LinkButton2");
TextBox text = (TextBox)e.Row.FindControl("Code");

if (text == null && lnk == null)
{
lnk.Visble = false;
}

else
{
lnk.Visible = True;
}
}
}


But in gridview output i get as follows

Course Code Days Startdate Enddate

ASM 5 05 May 2016 10 May 2016
12 May 2016 17 May 2016
21 May 2016 25 May 2016

In course column all the link button are visible false. i want only the second row and third row link button only visible false.

推荐答案

嗯。

你需要停下来想想你的代码更加谨慎:

Um.
You need to stop and think about your code a bit more carefully:
LinkButton lnk= (LinkButton)e.Row.FindControl("LinkButton2");
TextBox text = (TextBox)e.Row.FindControl("Code");
if (text == null && lnk == null)
    {
    lnk.Visble = false;
    }
else
    {
    lnk.Visible = True; 
    }

因此,如果变量 lnk 为null,则尝试访问它的Visible属性并将其设置为false!

如果它永远为null,那么该代码将立即失败并带有空引用异常。



另外,因为你总是设置相同的可见性按钮...它只设置一个按钮......



检查LinkBut​​ton或TextBox控件是否为空不检查其内容以查看是否为空的或空白的字符串......

我不打算为你解决这个问题,因为我觉得你需要退一步看看整个事情:我很漂亮确定这不是正确的方法,但我不知道你想要实现什么,所以我不能建议一个更好的...

So, if the variable lnk is null, you try to access it's Visible property and set it to false!
If it is ever null, that code will immediate fail with a null reference exception.

In addition, because you always set the visibility of the same button...it only ever sets the one button...

And checking if the LinkButton or TextBox controls are null doesn't check their content to see if that's empty or a blank string...
I'm not going to try and fix this for you, because I think you need to step back a bit and look at the whole thing: I'm pretty sure this isn't the right approach, but I have no idea what you are trying to achieve so I can't suggest a better one...


为什么不尝试添加一个列存储布尔值以确定链接按钮的可见性。根据db值,您始终可以使用三元运算来获得前端的可见性。
Why dont you try adding a column to store boolean value to determine the visibility of the link button. You can always use a ternary operation for the visibility at the front end depending on the db value.


这篇关于Lnk按钮应该是可见的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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