C# 在选定索引的Gridview中隐藏SelectedButton已更改

C# 在选定索引的Gridview中隐藏SelectedButton已更改,c#,gridview,linkbutton,C#,Gridview,Linkbutton,我在templatefield中有一个带有SelectButton的Gridview。一旦按下按钮,我希望这个按钮被隐藏。我知道 LinkButton SLCT = (LinkButton)GridView01.SelectedRow.FindControl("ButtonSelect"); SLCT.Visible = false; 我尝试用许多不同的方式声明按钮,使用行索引、单元格索引。但它总是抛出以下异常: System.NullReferenceException: Object re

我在templatefield中有一个带有SelectButton的Gridview。一旦按下按钮,我希望这个按钮被隐藏。我知道

LinkButton SLCT = (LinkButton)GridView01.SelectedRow.FindControl("ButtonSelect");
SLCT.Visible = false;
我尝试用许多不同的方式声明按钮,使用行索引、单元格索引。但它总是抛出以下异常:

System.NullReferenceException: Object reference not set to an instance of an object
用于指定控件的所有参数都是100%正确的,但错误始终相同

这上面有人吗?
Martin

您是否使用调试器查看了什么是
null
?是SLCT按钮为null您是否确定
SelectedRow
有一个控件
ButtonSelect
?我应用了相同的逻辑在同一个GridView中隐藏标签:Label SLCT=GridView01。SelectedRow.FindControl(“LabelSalesprice”)作为标签;SLCT.Visible=false,它可以工作。以模拟方式使用链接按钮有问题吗?那很痛。我检查了它一百万次,“SelectButton”不是“ButtonSelect”,如果您手动进行更正,就会出现这种情况。