Binding inner gridview

I am binding the inner gridview in the onrowdatabound of outer grid but i am not able do paging for the inner gridview which loads in the outer gridview rowdatabound method.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

On DataRowBound event of outer gridview set the datasource of child gridview. After setting, keep this datasource in ViewState . like;


And then on pageindexchanging event of inner gridview do this.

        GridView grdUserChild = (GridView)sender;

        DataTable dt = (DataTable)ViewState["InnerGridDS"];
        grdUserChild.PageIndex = e.NewPageIndex;
        grdUserChild.DataSource = dt;

It works for me. So should work for you too :)
SukeshjphAuthor Commented:
In my outer gridview rowcommand i am writing code like this.
DateTime Span = System.DateTime.Today.AddDays(-8);
        DateTime StartTime;
        DateTime EndTime;
        StartTime = Convert.ToDateTime(Span.AddDays(1).ToString());
        EndTime = Convert.ToDateTime(Span.AddDays(8).ToString());
        serviceObject = new Diaspora.Services.NetworkUpdateService();
        if (e.Row.RowType == DataControlRowType.DataRow)
            DataTable dt = new DataTable();
            LinkButton lnkbtnfriendsname = (LinkButton)e.Row.FindControl("lnkbtnFriendsBuddyID");
            GridView gvInnerForfriendsRowB = e.Row.FindControl("gvInnerForfriends") as GridView;

            if (Convert.ToBoolean(ViewState["DecideForWhich"]) == true)
                dt = serviceObject.FindOutFriendsFriend(Convert.ToInt64(lnkbtnfriendsname.Text), StartTime, EndTime);
                ViewState["InnerGridDS"] = dt;

                dt = serviceObject.FindOutFriendsFriend(Convert.ToInt64(lnkbtnfriendsname.Text), System.DateTime.Today);
                ViewState["InnerGridDS"] = dt;

            gvInnerForfriendsRowB.DataSource = dt;

as u told i also placed viewstate.But when i click on the page buttons then rowcommand event of childgrid is fired as i need to travel into anothe page on the button the row command is fired first i am not getting paging event fired.Can u suggest how can i go to onpageindex changing directly avoding onrowcommand of childgrid

here is rowcommand of child grid.

protected void gvInnerForfriends_rowcommand(object sender, GridViewCommandEventArgs e)
        int index = Convert.ToInt32(e.CommandArgument);
        Response.Redirect("../Default.aspx?Id=" + index);

On row command event you should handle action according to the command name.

create a switch/case on e.CommandName variable.

switch e.CommandName
 case "Select":

case "Page":


When you click a paging button, first row command fires, then page index changing event. On row command event, if you check the e.CommandName, you will see it is Page command. You wont handle it on row command. as I said, after row command paging event will fired. Do your staff there.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.