I am trying to set the top gridview's column's width to the body's column width and then the left columns height to the body's coloumns height. Here is my code:
<form id="form1" runat="server">
<div>
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell>
</asp:TableCell><asp:TableCell>
<asp:GridView ID="GridView2" runat="server" ShowHeader="false">
</asp:GridView>
</asp:TableCell></asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:GridView ID="GridView3" runat="server" ShowHeader="false">
</asp:GridView>
</asp:TableCell><asp:TableCell>
<asp:GridView ID="GridView4" runat="server" ShowHeader="false">
</asp:GridView>
</asp:TableCell></asp:TableRow>
</asp:Table>
</div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</form>
Here is the code behinde:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
DataTable dt3 = new DataTable();
DataRow row;
dt1.Columns.Add(new DataColumn("Description", Type.GetType("System.String")));
dt1.Columns.Add(new DataColumn("ROXORZZOZO!!", Type.GetType("System.String")));
dt1.Columns.Add(new DataColumn("MY", Type.GetType("System.String")));
row = dt1.NewRow();
row["Description"] = "WOOOO";
row["ROXORZZOZO!!"] = "EOOOOOOOOOOOOOOOOOOOOO!";
row["MY"] = "My time to shine!";
dt1.Rows.Add(row);
row = dt1.NewRow();
row["Description"] = "MO!";
row["ROXORZZOZO!!"] = "EOOOO!";
row["MY"] = "My time to dine!";
dt1.Rows.Add(row);
row = dt1.NewRow();
row["Description"] = "WOOOO";
row["ROXORZZOZO!!"] = "EOOOOOOOOOOOOOOOOOOOOO!Hey Guys,Today(Thursday) I need to leave early at three to take care of some personal business. Also, next Wednesday I’m going to be out of the office all day, taking a welding certification test. I’ll also send out an OOO form.";
row["MY"] = "My time to be fine!";
dt1.Rows.Add(row);
dt2.Columns.Add(new DataColumn("Description", Type.GetType("System.String")));
dt2.Columns.Add(new DataColumn("ROXORZZOZO!!", Type.GetType("System.String")));
dt2.Columns.Add(new DataColumn("MY", Type.GetType("System.String")));
row = dt2.NewRow();
row["Description"] = "Description";
row["ROXORZZOZO!!"] = "ROXORZZOZO!!";
row["MY"] = "MY";
dt2.Rows.Add(row);
dt3.Columns.Add(new DataColumn("Row Numbers", Type.GetType("System.String")));
row = dt3.NewRow();
row["Row Numbers"] = "1";
dt3.Rows.Add(row);
row = dt3.NewRow();
row["Row Numbers"] = "2";
dt3.Rows.Add(row);
row = dt3.NewRow();
row["Row Numbers"] = "3";
dt3.Rows.Add(row);
GridView3.DataSource = new DataView(dt3);
GridView2.DataSource = new DataView(dt2);
GridView4.DataSource = new DataView(dt1);
GridView2.DataBind();
GridView3.DataBind();
GridView4.DataBind();
SynchGridviews(GridView2, GridView3, GridView4);
}
}
protected void SynchGridviews(GridView top, GridView left, GridView body)
{
if (top.Width.Value > body.Width.Value)
{
body.Width = top.Width;
}
else
{
top.Width = body.Width;
}
if (left.Height.Value > body.Height.Value)
{
body.Height = left.Height;
}
else
{
left.Height = body.Height;
}
GridView2.DataBind();
GridView3.DataBind();
GridView4.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
SynchGridviews(GridView2, GridView3, GridView4);
}