[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1207
  • Last Modified:

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.
0
Sukeshjph
Asked:
Sukeshjph
  • 2
1 Solution
 
monarch_ilhanCommented:
On DataRowBound event of outer gridview set the datasource of child gridview. After setting, keep this datasource in ViewState . like;

ViewState["InnerGridDS"]=dt;

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;
        grdUserChild.DataBind();

It works for me. So should work for you too :)
0
 
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;

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

            }
            gvInnerForfriendsRowB.DataSource = dt;
            gvInnerForfriendsRowB.DataBind();


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 click.as 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);

    }
0
 
monarch_ilhanCommented:
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":
etc.
..
..

}

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.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now