T
Troy
I have been trying for 2 weeks to figure out how to
implement a table as a member variable that the user can
setup with the property designer with no luck. The code
below adds the table to the property designer, however it
will not write the HTML associated with the TABLE within
the custom server control tags unless you change the font
property within the table. For instance you can set the
ID of the table and its height and width then hit rebuild
and it all gets blown away because the table does'nt get
serialized.However set the ID,Width and Height again this
time change the Font property of the table to bold and it
magically writes the HTML code as shown in result 2,
which is exactly correct and what I want. Changing any
property value in the font of the table somehow triggers
VS to write the correct HTML..but changing any of the
table attributes doesnt do anything..you have to change
the font to get it to make any change...............
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing.Design;
using System.Web.UI.Design;
namespace RealGridII
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>
[ToolboxData("<{0}:RealGridControl runat=server></
{0}:RealGridControl>")]
public class RealGridControl :
System.Web.UI.WebControls.DataGrid
{
private Table m_myHeader;
/// <summary>
/// Constructor
/// </summary>
public RealGridControl()
{
m_myHeader = new Table();
}
[Category("LookHere"),NotifyParentProperty
(true),DesignerSerializationVisibility
(DesignerSerializationVisibility.Content),PersistenceMode
(PersistenceMode.InnerProperty)]
public Table myDatagrid
{
get
{
return m_myHeader;
}
set
{
m_myHeader = value;
}
}
/// <summary>
/// Render this control to the output
parameter specified.
/// </summary>
/// <param name="output"> The HTML writer
to write out to </param>
protected override void Render
(HtmlTextWriter output)
{
m_myHeader.RenderControl(output);
base.Render(output);
}
}
}
Result #1:
<form id="Form1" method="post" runat="server">
<cc1:realgridcontrol
id="RealGridControl2" style="Z-INDEX: 101; LEFT: 400px;
POSITION: absolute; TOP: 184px"
runat="server"
DataSource="<%# dataView1 %>" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn
DataField="EmployeeID" SortExpression="EmployeeID"
HeaderText="EmployeeID"></asp:BoundColumn>
<asp:BoundColumn
DataField="LastName" SortExpression="LastName"
HeaderText="LastName"></asp:BoundColumn>
<asp:BoundColumn
DataField="FirstName" SortExpression="FirstName"
HeaderText="FirstName"></asp:BoundColumn>
</Columns>
</cc1:realgridcontrol></form>
Result #2
<form id="Form1" method="post" runat="server">
<cc1:realgridcontrol
id="RealGridControl2" style="Z-INDEX: 101; LEFT: 400px;
POSITION: absolute; TOP: 184px"
runat="server"
DataSource="<%# dataView1 %>" AutoGenerateColumns="False">
<myDatagrid Font-
Bold="True" ID="fuku"></myDatagrid>
<Columns>
<asp:BoundColumn
DataField="EmployeeID" SortExpression="EmployeeID"
HeaderText="EmployeeID"></asp:BoundColumn>
<asp:BoundColumn
DataField="LastName" SortExpression="LastName"
HeaderText="LastName"></asp:BoundColumn>
<asp:BoundColumn
DataField="FirstName" SortExpression="FirstName"
HeaderText="FirstName"></asp:BoundColumn>
</Columns>
</cc1:realgridcontrol></form>
implement a table as a member variable that the user can
setup with the property designer with no luck. The code
below adds the table to the property designer, however it
will not write the HTML associated with the TABLE within
the custom server control tags unless you change the font
property within the table. For instance you can set the
ID of the table and its height and width then hit rebuild
and it all gets blown away because the table does'nt get
serialized.However set the ID,Width and Height again this
time change the Font property of the table to bold and it
magically writes the HTML code as shown in result 2,
which is exactly correct and what I want. Changing any
property value in the font of the table somehow triggers
VS to write the correct HTML..but changing any of the
table attributes doesnt do anything..you have to change
the font to get it to make any change...............
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing.Design;
using System.Web.UI.Design;
namespace RealGridII
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>
[ToolboxData("<{0}:RealGridControl runat=server></
{0}:RealGridControl>")]
public class RealGridControl :
System.Web.UI.WebControls.DataGrid
{
private Table m_myHeader;
/// <summary>
/// Constructor
/// </summary>
public RealGridControl()
{
m_myHeader = new Table();
}
[Category("LookHere"),NotifyParentProperty
(true),DesignerSerializationVisibility
(DesignerSerializationVisibility.Content),PersistenceMode
(PersistenceMode.InnerProperty)]
public Table myDatagrid
{
get
{
return m_myHeader;
}
set
{
m_myHeader = value;
}
}
/// <summary>
/// Render this control to the output
parameter specified.
/// </summary>
/// <param name="output"> The HTML writer
to write out to </param>
protected override void Render
(HtmlTextWriter output)
{
m_myHeader.RenderControl(output);
base.Render(output);
}
}
}
Result #1:
<form id="Form1" method="post" runat="server">
<cc1:realgridcontrol
id="RealGridControl2" style="Z-INDEX: 101; LEFT: 400px;
POSITION: absolute; TOP: 184px"
runat="server"
DataSource="<%# dataView1 %>" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn
DataField="EmployeeID" SortExpression="EmployeeID"
HeaderText="EmployeeID"></asp:BoundColumn>
<asp:BoundColumn
DataField="LastName" SortExpression="LastName"
HeaderText="LastName"></asp:BoundColumn>
<asp:BoundColumn
DataField="FirstName" SortExpression="FirstName"
HeaderText="FirstName"></asp:BoundColumn>
</Columns>
</cc1:realgridcontrol></form>
Result #2
<form id="Form1" method="post" runat="server">
<cc1:realgridcontrol
id="RealGridControl2" style="Z-INDEX: 101; LEFT: 400px;
POSITION: absolute; TOP: 184px"
runat="server"
DataSource="<%# dataView1 %>" AutoGenerateColumns="False">
<myDatagrid Font-
Bold="True" ID="fuku"></myDatagrid>
<Columns>
<asp:BoundColumn
DataField="EmployeeID" SortExpression="EmployeeID"
HeaderText="EmployeeID"></asp:BoundColumn>
<asp:BoundColumn
DataField="LastName" SortExpression="LastName"
HeaderText="LastName"></asp:BoundColumn>
<asp:BoundColumn
DataField="FirstName" SortExpression="FirstName"
HeaderText="FirstName"></asp:BoundColumn>
</Columns>
</cc1:realgridcontrol></form>