3
votes

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!

3

3 Answers

10
votes
GridViewRow PagerRow = GridView1.BottomPagerRow;
LinkButton b = (LinkButton)PagerRow.FindControl("lnkbtnPrevious"));
1
votes

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"));
0
votes

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