문제

I have multiple GridView on a page, and they are all pagable. I need to handle the paging in OnPageIndexChanging event, but I'd rather not write the same code for each GridView.

So how can I get the GridView object id from the sender? I'm trying to do something like the following....

protected void PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView gridView = (GridView)sender.ID;

    gridView.PageIndex = e.NewPageIndex;
    gridView.DataBind();
}

This way I could call the same event handler for all the GridViews and not have to write a new even handler for each one? I'm just not sure how to get the ID of the GridView firing the event :(

any help appreciated!

도움이 되었습니까?

해결책

It's even simpler:

GridView gridView = (GridView)sender;

The sender argument is always the control that triggered the event.

다른 팁

protected void PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView gv= sender as GridView;

    if(gv!=null){
        gridView.PageIndex = e.NewPageIndex;
        gridView.DataBind();
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top