By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,021 Members | 1,321 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,021 IT Pros & Developers. It's quick & easy.

changing the content of header template while the page is loading

P: n/a
I am using a datalist control in my page and it has a header template.
In the header template I have a table control with table rows and
table cells. While the page is loading I am trying to change the
contents of one of the cells. By using Page.FindControl() I am getting
an error message that it cannot find an instance of an object.
I am giving the page code and code behind.

I am trying to insert a literal control in the table cell with
id="celltwo", but not able to do so. Any one has any answers.

-----------------------
<%@ Page Language="vb" AutoEventWireUp ="False"
Codebehind="WebForm2.aspx.vb" Inherits="ATMTransactions.WebForm2"%>

<html><head>
<title>PageControlsAdd</title>
</head>
<body>
<form id="f1" runat="server">
<asp:Datalist id="list" runat="server">
<headertemplate>
<asp:Table id="t5" runat="server" GridLines="both"
BorderWidth="1px">
<asp:TableRow>
<asp:TableCell id="cellone">Cell 1</asp:TableCell>
<asp:TableCell id="celltwo">Cell 2</asp:TableCell>
</asp:TableRow>
</asp:table>
<asp:Button id="joincrowd" text="Join The Crowd" runat="server"/>
</headertemplate>
</asp:datalist>
</form>
</body>
</html>
-------------- Code behind---------------------
Public Class WebForm2
Inherits System.Web.UI.Page
Protected WithEvents t5 As System.Web.UI.WebControls.Table
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
' This example just injects some plain text
Dim whatever As control

whatever = Page.FindControl("celltwo")
whatever.Controls.Add(New LiteralControl("Surpris"))

' This example injects some table rows and cells
End Sub

End Class
Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.