nested Gridview overflows DIV size


A

Abhijit

Strange behavior with ASP.NET 2.0

I have a simple nested gridview (for sample, each with just two columns)

The gridview is placed inside a DIV which has height fixed and "overflow =
auto" to control the flow of contents inside DIV and show scrollbars
automaticallty.

The parent GRIDVIEW gets clipped correctly but the child one keeps rendering
outside the DIV bounds

Here is the sample ASPX (ignoring other obvious stuff)
I don't know if I can attach an screenshot to demonstrate the problem.

/////// ASP ////////////////
.......
<div style="height:100px;overflow:auto;">
<asp:GridView id="GV_Parent" ......>
<asp:BoundField DataField="ParentVal1" />
<asp:TemplateField HeaderText="" ShowHeader="False">
<ItemTemplate>
<asp:GridView id="GV_Child" ....
<asp:BoundField DataField="ChildVal1" />
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
</div>
............
/////////////// C# CodeBehind ////////////////
/////// Ignoring other stuff ////////////

public class myDataChild
{
private int iVal;
public int ChildVal1
{
get { return iVal; }
set { iVal = value; }
}

}
public class myDataParent
{
private int iVal;
public List<myDataChild> iChildList ;
public int ParentVal1
{
get { return iVal; }
set { iVal = value; }
}

}

public partial class MyPage : System.Web.UI.Page
{
List<myDataParent> DataForBinding = new List<myDataParent>();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
for(int iC = 0; iC < 30; iC++)
{
myDataParent item = new myDataParent ;
item.ParentVal1 = iC ;
for(int jC = 0; jC < 2; jC++)
{
myDataChild chItem = new myDataChild ;
chItem.ChildVal1 = jC ;
item.Add(chItem) ;
}
DataForBinding.Add(item);
}
GV_Parent.DataSource = DataForBinding;
GV_Parent.DataBind();
}
}

protected void gv_RowDataBound........
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
myDataParent pData = (myDataParent)e.Row.DataItem;
GridView gv = (GridView)e.Row.FindControl("GV_Child");
if (null != gv)
{
gv.DataSource = pData.iChildList;
gv.DataBind();
}
}
}
}
///////////////////////
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top