Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey...

I have Gridview name of PlayerGridViewPlayer and In Which colums PlayerName,Country,Zip And at last Nested gridview name of GV2. i m tried to fill GV2.

Please give some example of How to fill nested gridview ..in the gridview

m received null exception from GV2
C#
Gridview GV2= (GridView)PlayerGridView.FindControl("Gv2"); 

GV2.Datasource=ds;// at This position gridview null exception
Posted
Updated 28-Jul-11 20:33pm
v2

Bind that Gridview in RowDataBound Event Like Below

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)// Bind nested grid view with parent grid view
        {
           // int Id =Convert.ToInt32(( (Label)e.Row.FindControl("Label3")).Text);
            GridView childgrd = (GridView)e.Row.FindControl("GridView2"); // find nested grid view from paretn grid veiw
            childgrd.DataSource = ds;
            childgrd.DataBind();
          }
    }
 
Share this answer
 
Hi,
Use this if ur binding data at the time of databinding


C++
protected void gv_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow) {
        GridView gv = e.Row.FindControl("GridView2");
        SqlDataSource dbSrc = new SqlDataSource();
        dbSrc.ConnectionString = ConfigurationManager.ConnectionStrings("NorthwindConnectionString2").ConnectionString;
        dbSrc.SelectCommand = "SELECT * FROM Orders WHERE CustomerID = '" + e.Row.DataItem("CustomerID").ToString + "' ORDER BY OrderDate";

        gv.DataSource = dbSrc;
        gv.DataBind();
    }
}
 
Share this answer
 
Thanks Both of u...
This Method work....
 
Share this answer
 
Can we fill Nested Gridview Without Using Row Data Bound..
 
Share this answer
 
C++
if u want only when particular row selected time then use this in selectedindexchange event of gridview


C#
protected void gvContacts_SelectedIndexChanged(object sender, EventArgs e)
   
{
GridView gv = (GridView)gvContacts.SelectedRow.FindControl("gv");
gvCs.DataSource = dt;
gvCs.DataBind();


}
 
Share this answer
 
v2
but this event under of Gridview without using gridview event fill nested gridview.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900