![]() |
|
|
| Subject:
ASP.Net Datalist
Category: Computers > Programming Asked by: gums-ga List Price: $5.00 |
Posted:
05 Feb 2004 09:25 PST
Expires: 06 Mar 2004 09:25 PST Question ID: 303794 |
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 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 DataList
whatever = CType(Page.FindControl("mydatalist"), DataList)
Dim whatever1 As Control = whatever.FindControl("celltwo")
whatever1.Controls.Add(New LiteralControl("hello"))
End Sub
End Class |
|
| There is no answer at this time. |
|
| Subject:
Re: ASP.Net Datalist
From: amethyst-ga on 13 Feb 2004 01:57 PST |
You have to Handle ItemCreated Event of the DataList and then use the
EventArgs argument to get the reference of the control.
eg.
Private Sub DataList1_ItemCreated(Sender As Object,e As DataListItemEventHandler )
If e.Item.ItemType =ListItemType.Header
Dim cell as TableCell = CType(e.Item.FindControl("t5"),Table).Cells(1)
End If
End Sub |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |