3

I am trying to access a LinkButton that is inside a PagerTemplate in a GridView.

However, I am getting a NullReferenceException and I don't know what I am doing wrong here.

I have tried the following...

((LinkButton)GridView1.BottomPagerRow.FindControl("lnkbtnPrevious"));
((LinkButton)GridView1.FindControl("lnkbtnPrevious"));

Can someone please help?

Thanks!

NullReference
  • 83
  • 1
  • 2
  • 4

3 Answers3

10
GridViewRow PagerRow = GridView1.BottomPagerRow;
LinkButton b = (LinkButton)PagerRow.FindControl("lnkbtnPrevious"));
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
sujit kumar m
  • 101
  • 1
  • 3
1

Make sure you have already created the link button in the PagerTemplate with the ID "lnkbtnPrevious" and the PagerSettings Position="Bottom" the following will get you access to the link button.

LinkButton lb = (LinkButton)((GridView1.BottomPagerRow).FindControl("lnkbtnPrevious"));
Charles
  • 11
  • 1
0

First create a link button in pagertemplate for gird and give id= "LB"

work this in code in databound event of gridview

protected void grid_DataBound(object sender, EventArgs e)
{
 LinkButton lb = (LinkButton)grid.BottomPagerRow.FindControl("LB");
}

this will work

sth
  • 222,467
  • 53
  • 283
  • 367