Monday, January 27, 2014

Binding Nested Detailsview in Gridview

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            GridViewRow row = e.Row;

            // Make sure we aren't in header/footer rows
            if (row.DataItem == null)
            {
                return;
            }

            DetailsView dv = (DetailsView)row.FindControl("DetailsView1");

            List<[object]> aList = List<[object]>();

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                aList[e.Row.RowIndex].Name = aList[e.Row.RowIndex].Name;

                dv.DataSource = aList.Where(u => u.ID == Convert.ToInt32(aList[e.Row.RowIndex].Address)).ToList();
                dv.DataBind();
            }
        }