开发者

access repeater control and change their properties

I am trying to either开发者_高级运维 disable / hide the lnkDelete button that is located inside repeater control. I used this method, however I get an error message: Object reference not set to an instance of an object. I am not sure what seems to be the problem. I am able to use intellesense to show the Visible property of the control, this proof to me that I do have scope to the control inside the repeater, anyone can help. thanks

    protected void rptCAP_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        var lnkDel = e.Item.FindControl("lnkDelete").Visible = false;
      }

Bob white


you need to add an if statement to check if the itemtype is an item or alternating item and not header item or footer item:

If (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){
 var lnkDel = e.Item.FindControl("lnkDelete").Visible = false;

   }


Bob it would seem you're trying to set the Visible property even when the FindControl doesn't return a control.

You should probably do something like

var lnkDel = e.Item.FindControl("lnkDelete");
if (lnkDel != null)
  lnkDel.Visible = false;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜