Google Answers Logo
View Question
Q: ASP.Net Datalist ( No Answer,   1 Comment )
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"%>

<form id="f1" runat="server">
 <asp:Datalist id="list" runat="server">
    <asp:Table id="t5" runat="server" GridLines="both"
        <asp:TableCell id="cellone">Cell 1</asp:TableCell>
        <asp:TableCell id="celltwo">Cell 2</asp:TableCell>
    <asp:Button id="joincrowd" text="Join The Crowd" runat="server"/>

-------------- 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

    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
        'Do not modify it using the code editor.
    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.


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

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy