Click to See Complete Forum and Search --> : Help: add attribute to pager linkbuttons gridview !
bxlbjorn
10-02-2007, 05:31 AM
Hi all,
I would like to add some client side javascript (linkbutton.Attributes.Add("onclick", "someCode()")
to the pager links at the bottom of my gridview (1 2 3 4 5 6 ...).
Can anyone help ?
On what event should this be done (rowcreated or prerender) ?
How can I access them to add the attribute ?
Thanks,
Björn
lmf232s
10-02-2007, 09:23 AM
Try it on RowCreated.
Protected Sub gvResults_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvResults.RowCreated
Select Case e.Row.RowType
Case DataControlRowType.Footer
Dim lb As LinkButton = CType(e.Row.FindControl("ControlName"), LinkButton)
lb.Attributes.Add("onclick", "someCode()")
End Select
End Sub
bxlbjorn
10-02-2007, 09:35 AM
Thanks, but the problem with this solution is that the controls (the pager linkbuttons) are created dynamically by the gridview and I therefore don't know what the ID of the control is, so FindControl seems out of the question.
More then that, depending on the pager settings, there are several linkbuttons (shown as "1 2 3 4 5 6 ...") so some sort of loop should at least be part of the solution.
Thanks for helping,
Björn
lotuzwine
10-02-2007, 09:55 AM
sorry, wrong code, delete this
Cstick
10-02-2007, 09:21 PM
Set the Pagerstyle-cssclass attribute of the gridview. Then on the window load event you can loop through each <a> element that is a child of the element with the pagerstyle-cssclass name and hook the click event to the function you want to call.