Adding webcontrols.table to aspx - not rendering

  • Thread starter Thread starter Sue
  • Start date Start date
S

Sue

On code-behind page:
(attributes set programatically for each of these elements)
linkbutton added to tablecell
textbox added to tablecell
tablecells added to tablerow
tablerow added to table (table.ID is TestTable)
On .aspx page:
<HeaderTemplate>
<asp:Table ID="TestTable" runat="Server" />
</HeaderTemplate>

Source code on .aspx page in browser shows the table and it's controls are
correctly created and placed. Controls for the Linkbutton and Textbox do
not display in browser. I suspect it has something to do with the
runat="server" attribute for the linkbutton or textbox for which I do not
find an attribute I can set (e.g. linkbutton.runat = "server"). Any ideas
on how I can get these elements to display?

tia,
Sue W.
 
Hi Sue,

This problem doesn't occur to the following code snippet. Does it work on
your side? If so, you may want to show me the code snippet on your side so
that I can test it. Thanks.

private void Page_Load(object sender, System.EventArgs e)
{
int numrows = 3;
int numcells = 2;
for (int j=0; j<numrows; j++)
{
TableRow r = new TableRow();
for (int i=0; i<numcells; i++)
{
TableCell c = new TableCell();
LinkButton lb=new LinkButton ();

lb.Text=i.ToString();
if(i==0)c.Controls.Add(lb);
else c.Controls.Add(new TextBox());
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}
}

Best Regards,
Lewis Wang
Support Professional

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
| MIME-Version: 1.0
| X-MIMETrack: Serialize by Notes Client on Susan L WILLIS/MUL/OJD(Release
6.0.1|February
| 07, 2003) at 07/23/2003 11:45:57 AM,
| Serialize complete at 07/23/2003 11:45:57 AM,
| Serialize by Notes Client on Susan L WILLIS/MUL/OJD(Release
6.0.1|February
| 07, 2003) at 07/23/2003 11:46:02 AM,
| Serialize complete at 07/23/2003 11:46:02 AM
| From: (e-mail address removed)
| Subject: Adding webcontrols.table to aspx - not rendering
| X-Newsreader: Lotus Notes Release 6.0.1 February 07, 2003
| Content-Type: text/plain; charset="US-ASCII"
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.general
| Date: Wed, 23 Jul 2003 11:46:03 -0700
| NNTP-Posting-Host: 159.121.96.200
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:102197
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| On code-behind page:
| (attributes set programatically for each of these elements)
| linkbutton added to tablecell
| textbox added to tablecell
| tablecells added to tablerow
| tablerow added to table (table.ID is TestTable)
| On .aspx page:
| <HeaderTemplate>
| <asp:Table ID="TestTable" runat="Server" />
| </HeaderTemplate>
|
| Source code on .aspx page in browser shows the table and it's controls
are
| correctly created and placed. Controls for the Linkbutton and Textbox do
| not display in browser. I suspect it has something to do with the
| runat="server" attribute for the linkbutton or textbox for which I do not
| find an attribute I can set (e.g. linkbutton.runat = "server"). Any ideas
| on how I can get these elements to display?
|
| tia,
| Sue W.
|
|
 
Hi Sue,

Thank you for your feedback.

Do you want to add a textbox and a linkbutton into table programmingly,
then put the table into a HeaderTemplate of datagrid's column? The
following code snippet demonstrates this.

If I misunderstood your concern, would you please provide more explanations
on your requirement? Thank you.

Dim CaseNumberHeaderTable As Table

Private Sub DataGrid1_ItemDataBound(ByVal sender As System.Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Header Then
CaseNumberHeaderTable =
CType(e.Item.FindControl("CaseNumberHeaderTable"), Table)
setCaseNumberHeaderTable()
End If

End Sub

Private Sub setCaseNumberHeaderTable()

Dim CaseNumberHRow1 As TableRow = New TableRow
Dim CaseNumberHRow2 As TableRow = New TableRow
Dim CaseNumberHCell1 As TableCell = New TableCell
Dim CaseNumberHCell2 As TableCell = New TableCell

Dim CaseNumberSortButton As LinkButton = New LinkButton
Dim CaseNumberFilterBox As TextBox = New TextBox

CaseNumberSortButton.ID = "CaseNumberSortButton"
CaseNumberSortButton.Text = "Sort CaseNo"
CaseNumberSortButton.ToolTip = "Click to sort the case number
column"

CaseNumberFilterBox.ID = "CaseNumberFilterBox"
CaseNumberFilterBox.ToolTip = "Enter case number on which to filter
records"

CaseNumberHCell1.VerticalAlign = VerticalAlign.Bottom
CaseNumberHCell1.HorizontalAlign = HorizontalAlign.Center
CaseNumberHCell1.Controls.Add(CaseNumberSortButton)

CaseNumberHCell2.VerticalAlign = VerticalAlign.Top
CaseNumberHCell2.Text = "Filter by: <BR><HR><BR>"
CaseNumberHCell2.Controls.Add(CaseNumberFilterBox)
CaseNumberHRow1.Controls.Add(CaseNumberHCell1)
CaseNumberHRow2.Controls.Add(CaseNumberHCell2)
CaseNumberHeaderTable.Controls.Add(CaseNumberHRow1)
CaseNumberHeaderTable.Controls.Add(CaseNumberHRow2)
CaseNumberHeaderTable.ID = "CaseNumberHeaderTable"
CaseNumberHeaderTable.BorderColor = Color.Blue
End Sub


Lewis Wang

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| Content-Class: urn:content-classes:message
| From: "Sue" <[email protected]>
| Sender: "Sue" <[email protected]>
| References: <#[email protected]>
<[email protected]>
| Subject: RE: Adding webcontrols.table to aspx - not rendering
| Date: Thu, 24 Jul 2003 11:38:45 -0700
| Lines: 87
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNSEtCmGhmPnX8ZQxeVikG/sDAnmg==
| Newsgroups: microsoft.public.dotnet.general
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:102328
| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| >your side? If so, you may want to show me the code
| snippet on your side so
| >that I can test it. Thanks.
|
| Lewis, tried your code, but I'm working in VB and
| couldn't remember half of how to get things set up for C
| (#?). I do have a similar table working just find
| further up in the web page. It's not part of a datagrid
| though. Below is the relevant code for this problem.
|
| Protected WithEvents CaseNumberSortButton As LinkButton =
| LinkButton
| Protected WithEvents CaseNumberFilterBox As TextBox = New
| TextBox
| Protected WithEvents CaseNumberHeaderTable As Table = New
| Table
| Protected WithEvents CaseNumberHRow1 As TableRow = New
| TableRow
| Protected WithEvents CaseNumberHRow2 As TableRow = New
| TableRow
| Protected WithEvents CaseNumberHCell1 As TableCell = New
| TableCell
| Protected WithEvents CaseNumberHCell2 As TableCell = New
| TableCell
|
| Private Sub Page_Load(ByVal sender As System.Object,
| ByVal e As System.EventArgs) Handles MyBase.Load
| Call setCaseNumberHeaderTable()
| End Sub
|
| Public Sub setCaseNumberHeaderTable()
| With CaseNumberSortButton
| .ID = "CaseNumberSortButton"
| .Text = "Sort CaseNo"
| .ToolTip = "Click to sort the case number column"
| End With
| With CaseNumberFilterBox
| .ID = "CaseNumberFilterBox"
| .ToolTip = "Enter case number on which to filter
| records"
| End With
| With Me.CaseNumberHCell1
| .VerticalAlign = VerticalAlign.Bottom
| .HorizontalAlign = HorizontalAlign.Center
| .Controls.Add(CaseNumberSortButton)
| End With
| With CaseNumberHCell2
| .VerticalAlign = VerticalAlign.Top
| .Text = "Filter by: <BR><HR><BR>"
| .Controls.Add(CaseNumberFilterBox)
| End With
| With Me.CaseNumberHRow1
| .Controls.Add(CaseNumberHCell1)
| End With
| With CaseNumberHRow2
| .Controls.Add(CaseNumberHCell2)
| End With
| With CaseNumberHeaderTable
| .Controls.Add(CaseNumberHRow1)
| .Controls.Add(CaseNumberHRow2)
| .ID = "CaseNumberHeaderTable"
| .Width.Percentage(100)
| End With
| End Sub
|
| .aspx file:
|
| <asp:datagrid id=DG runat="server">
| <Columns>
| <asp:TemplateColumn SortExpression="CaseNo">
| <HeaderTemplate>
| <asp:Table ID="CaseNumberHeaderTable"
| Runat="Server" />
| </HeaderTemplate>
| ......
| </asp:TemplateColumn>
| </Columns>
| </asp:Datagrid>
|
| Any help appreciated...
|
| Sue
|
|
|
|
|
|
 
If I misunderstood your concern, would you please
provide more explanations
on your requirement? Thank you.

This is exactly what I wish to do. I have tried the code
below (modified for my object names) and got an invalid
cast error message at the CType line. I know this is
simple, I'm just not tripping onto the correct syntax
<sigh>. I've tried various options for the CType without
success. Any other ideas?

tia,
Sue
 
Hi Sue,

The Type should be the same as control's type <asp:Table
ID="CaseNumberHeaderTable" Runat="Server" />. Otherwise, there will be an
error. If FindControl menthod returns nothing, there will also be an error.
You can use code similar to the following to perform the cast.

Private Sub DataGrid1_ItemDataBound(ByVal sender As System.Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound

If e.Item.ItemType = ListItemType.Header Then
Dim ctrl As Control =
e.Item.FindControl("CaseNumberHeaderTable")
If Not ctrl Is Nothing Then
CaseNumberHeaderTable = CType(ctrl, Table)
setCaseNumberHeaderTable()
End If
End If

End Sub

Please let know if it helps. Thanks.

Lewis

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
| Content-Class: urn:content-classes:message
| From: "Sue" <[email protected]>
| Sender: "Sue" <[email protected]>
| References: <#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: RE: Adding webcontrols.table to aspx - not rendering
| Date: Mon, 28 Jul 2003 10:03:35 -0700
| Lines: 204
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNVKi7XO2W/Wc7XRJSgT85DFF8sFw==
| Newsgroups: microsoft.public.dotnet.general
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:102600
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| >If I misunderstood your concern, would you please
| provide more explanations
| >on your requirement? Thank you.
|
| This is exactly what I wish to do. I have tried the code
| below (modified for my object names) and got an invalid
| cast error message at the CType line. I know this is
| simple, I'm just not tripping onto the correct syntax
| <sigh>. I've tried various options for the CType without
| success. Any other ideas?
|
| tia,
| Sue
|
| >
| >Dim CaseNumberHeaderTable As Table
| >
| >Private Sub DataGrid1_ItemDataBound(ByVal sender As
| System.Object, ByVal e
| >As System.Web.UI.WebControls.DataGridItemEventArgs)
| Handles
| >DataGrid1.ItemDataBound
| > If e.Item.ItemType = ListItemType.Header Then
| > CaseNumberHeaderTable =
| >CType(e.Item.FindControl("CaseNumberHeaderTable"), Table)
| > setCaseNumberHeaderTable()
| > End If
| >
| > End Sub
| >
| >Private Sub setCaseNumberHeaderTable()
| >
| > Dim CaseNumberHRow1 As TableRow = New TableRow
| > Dim CaseNumberHRow2 As TableRow = New TableRow
| > Dim CaseNumberHCell1 As TableCell = New TableCell
| > Dim CaseNumberHCell2 As TableCell = New TableCell
| >
| > Dim CaseNumberSortButton As LinkButton = New
| LinkButton
| > Dim CaseNumberFilterBox As TextBox = New TextBox
| >
| > CaseNumberSortButton.ID = "CaseNumberSortButton"
| > CaseNumberSortButton.Text = "Sort CaseNo"
| > CaseNumberSortButton.ToolTip = "Click to sort
| the case number
| >column"
| >
| > CaseNumberFilterBox.ID = "CaseNumberFilterBox"
| > CaseNumberFilterBox.ToolTip = "Enter case number
| on which to filter
| >records"
| >
| > CaseNumberHCell1.VerticalAlign =
| VerticalAlign.Bottom
| > CaseNumberHCell1.HorizontalAlign =
| HorizontalAlign.Center
| > CaseNumberHCell1.Controls.Add
| (CaseNumberSortButton)
| >
| > CaseNumberHCell2.VerticalAlign =
| VerticalAlign.Top
| > CaseNumberHCell2.Text = "Filter by: <BR><HR><BR>"
| > CaseNumberHCell2.Controls.Add
| (CaseNumberFilterBox)
| > CaseNumberHRow1.Controls.Add(CaseNumberHCell1)
| > CaseNumberHRow2.Controls.Add(CaseNumberHCell2)
| > CaseNumberHeaderTable.Controls.Add
| (CaseNumberHRow1)
| > CaseNumberHeaderTable.Controls.Add
| (CaseNumberHRow2)
| > CaseNumberHeaderTable.ID
| = "CaseNumberHeaderTable"
| > CaseNumberHeaderTable.BorderColor = Color.Blue
| > End Sub
| >
| >
| >Lewis Wang
| >
| >This posting is provided "AS IS" with no warranties, and
| confers no rights.
| >--------------------
| >| Content-Class: urn:content-classes:message
| >| From: "Sue" <[email protected]>
| >| Sender: "Sue" <[email protected]>
| >| References: <#[email protected]>
| ><[email protected]>
| >| Subject: RE: Adding webcontrols.table to aspx - not
| rendering
| >| Date: Thu, 24 Jul 2003 11:38:45 -0700
| >| Lines: 87
| >| Message-ID: <[email protected]>
| >| MIME-Version: 1.0
| >| Content-Type: text/plain;
| >| charset="iso-8859-1"
| >| Content-Transfer-Encoding: 7bit
| >| X-Newsreader: Microsoft CDO for Windows 2000
| >| X-MimeOLE: Produced By Microsoft MimeOLE
| V5.50.4910.0300
| >| Thread-Index: AcNSEtCmGhmPnX8ZQxeVikG/sDAnmg==
| >| Newsgroups: microsoft.public.dotnet.general
| >| Path: cpmsftngxa06.phx.gbl
| >| Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.general:102328
| >| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| >| X-Tomcat-NG: microsoft.public.dotnet.general
| >|
| >| >your side? If so, you may want to show me the code
| >| snippet on your side so
| >| >that I can test it. Thanks.
| >|
| >| Lewis, tried your code, but I'm working in VB and
| >| couldn't remember half of how to get things set up for
| C
| >| (#?). I do have a similar table working just find
| >| further up in the web page. It's not part of a
| datagrid
| >| though. Below is the relevant code for this problem.
| >|
| >| Protected WithEvents CaseNumberSortButton As
| LinkButton =
| >| LinkButton
| >| Protected WithEvents CaseNumberFilterBox As TextBox =
| New
| >| TextBox
| >| Protected WithEvents CaseNumberHeaderTable As Table =
| New
| >| Table
| >| Protected WithEvents CaseNumberHRow1 As TableRow = New
| >| TableRow
| >| Protected WithEvents CaseNumberHRow2 As TableRow = New
| >| TableRow
| >| Protected WithEvents CaseNumberHCell1 As TableCell =
| New
| >| TableCell
| >| Protected WithEvents CaseNumberHCell2 As TableCell =
| New
| >| TableCell
| >|
| >| Private Sub Page_Load(ByVal sender As System.Object,
| >| ByVal e As System.EventArgs) Handles MyBase.Load
| >| Call setCaseNumberHeaderTable()
| >| End Sub
| >|
| >| Public Sub setCaseNumberHeaderTable()
| >| With CaseNumberSortButton
| >| .ID = "CaseNumberSortButton"
| >| .Text = "Sort CaseNo"
| >| .ToolTip = "Click to sort the case number column"
| >| End With
| >| With CaseNumberFilterBox
| >| .ID = "CaseNumberFilterBox"
| >| .ToolTip = "Enter case number on which to filter
| >| records"
| >| End With
| >| With Me.CaseNumberHCell1
| >| .VerticalAlign = VerticalAlign.Bottom
| >| .HorizontalAlign = HorizontalAlign.Center
| >| .Controls.Add(CaseNumberSortButton)
| >| End With
| >| With CaseNumberHCell2
| >| .VerticalAlign = VerticalAlign.Top
| >| .Text = "Filter by: <BR><HR><BR>"
| >| .Controls.Add(CaseNumberFilterBox)
| >| End With
| >| With Me.CaseNumberHRow1
| >| .Controls.Add(CaseNumberHCell1)
| >| End With
| >| With CaseNumberHRow2
| >| .Controls.Add(CaseNumberHCell2)
| >| End With
| >| With CaseNumberHeaderTable
| >| .Controls.Add(CaseNumberHRow1)
| >| .Controls.Add(CaseNumberHRow2)
| >| .ID = "CaseNumberHeaderTable"
| >| .Width.Percentage(100)
| >| End With
| >| End Sub
| >|
| >| .aspx file:
| >|
| >| <asp:datagrid id=DG runat="server">
| >| <Columns>
| >| <asp:TemplateColumn SortExpression="CaseNo">
| >| <HeaderTemplate>
| >| <asp:Table ID="CaseNumberHeaderTable"
| >| Runat="Server" />
| >| </HeaderTemplate>
| >| ......
| >| </asp:TemplateColumn>
| >| </Columns>
| >| </asp:Datagrid>
| >|
| >| Any help appreciated...
| >|
| >| Sue
| >|
| >|
| >|
| >|
| >|
| >|
| >
| >.
| >
|
 
Hi Sue,

I am glad to hear it. Thanks very much for participating the community.

Lewis

--------------------
| Content-Class: urn:content-classes:message
| From: "Sue" <[email protected]>
| Sender: "Sue" <[email protected]>
| References: <#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: RE: Adding webcontrols.table to aspx - not rendering
| Date: Tue, 29 Jul 2003 08:41:29 -0700
| Lines: 12
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNV5+DwpsTgGSItQI60DEU5KS6ZWw==
| Newsgroups: microsoft.public.dotnet.general
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:102714
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| Aha...in my HTML on the .aspx page, I had used
| <table...>. Once I changed it to <asp:table> things
| started working. Thanks for the help with this - I knew
| it was something simple that I just wasn't seeing. Live
| and learn.
|
| Sue
|
| >The Type should be the same as control's type <asp:Table
| >ID="CaseNumberHeaderTable" Runat="Server" />.
|
|
|
 
Back
Top