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
atagrid>
| >|
| >| Any help appreciated...
| >|
| >| Sue
| >|
| >|
| >|
| >|
| >|
| >|
| >
| >.
| >
|