473,473 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Accessing Child Controls inside a dataset or datagird

Ok fellow C# developers:

How do creat an instance of an object inside a dataset or datagrid.

Example I need to have a placeholder inside a dataset. Any help would be
great.
Nov 17 '05 #1
4 2250
Sorry I was revering to a datalist. I need to populate a placeholder inside
a datalist with dynamic content when the page loads. If I just place the
following:

<asp:datalist id="DataList_RoundApplause" runat="server" width="428px"
borderstyle="Double" cellpadding="5">
<headertemplate>
<b><font size="2">
<%# str_MonthName %>
<%# str_Year %>
Winners</font></b>
</headertemplate>
<itemstyle borderwidth="1px" bordercolor="#C0C000"></itemstyle>
<itemtemplate>
Name: <b>
<%# DataBinder.Eval(Container.DataItem, "Emp_Last_Name") %>
,
<%# DataBinder.Eval(Container.DataItem, "Emp_First_Name") %>
</b>
<br>
Department: <b>
<%# DataBinder.Eval(Container.DataItem, "Emp_Department") %>
</b>
<br>
Date Awarded: <b>
<%# DataBinder.Eval(Container.DataItem, "Awarded_Date") %>
</b>
<br>
Date Awarded: <b>
<%# DataBinder.Eval(Container.DataItem, "Emp_Lan_ID") %>
</b>
<br>
<br>
<br>
Award Summary:<br>
<b>
<%# DataBinder.Eval(Container.DataItem, "Award_Summary") %>
</b>
<asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>
</itemtemplate>
</asp:datalist>

I get an error that there is not an instance of the placeholder object.

Any help would be great.
"Moojjoo" wrote:
Ok fellow C# developers:

How do creat an instance of an object inside a dataset or datagrid.

Example I need to have a placeholder inside a dataset. Any help would be
great.

Nov 17 '05 #2
The designer does not create a reference to your place holder control for one important reason: It may be repeated.

Think about the situation:

1. You create a "template" for each item in the list
2. The list is bound at runtime and the template is instantiated for every item in the list
3. Now, there are multiple placeholder controls in your list (one for each item in the list)

If the designer serialized a field for "PlaceHolder1", at runtime which one of those in the list would it reference?

To access the placeholder, you must index into the Controls of the item you are after. For instance:

int interestingItem = 0;
DataList_RoundApplause.Items[interestingItem].Controls[1] as PlaceHolder

(I specified index "1" because the first control in each instantiated template will be a LiteralControl for all of the text that you
added prior to the PlaceHolder)

Hope it helps

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Moojjoo" <Mo*****@discussions.microsoft.com> wrote in message news:E1**********************************@microsof t.com...
Sorry I was revering to a datalist. I need to populate a placeholder inside
a datalist with dynamic content when the page loads. If I just place the
following:

<asp:datalist id="DataList_RoundApplause" runat="server" width="428px"
borderstyle="Double" cellpadding="5">
<headertemplate>
<b><font size="2">
<%# str_MonthName %>
<%# str_Year %>
Winners</font></b>
</headertemplate>
<itemstyle borderwidth="1px" bordercolor="#C0C000"></itemstyle>
<itemtemplate>
Name: <b>
<%# DataBinder.Eval(Container.DataItem, "Emp_Last_Name") %>
,
<%# DataBinder.Eval(Container.DataItem, "Emp_First_Name") %>
</b>
<br>
Department: <b>
<%# DataBinder.Eval(Container.DataItem, "Emp_Department") %>
</b>
<br>
Date Awarded: <b>
<%# DataBinder.Eval(Container.DataItem, "Awarded_Date") %>
</b>
<br>
Date Awarded: <b>
<%# DataBinder.Eval(Container.DataItem, "Emp_Lan_ID") %>
</b>
<br>
<br>
<br>
Award Summary:<br>
<b>
<%# DataBinder.Eval(Container.DataItem, "Award_Summary") %>
</b>
<asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>
</itemtemplate>
</asp:datalist>

I get an error that there is not an instance of the placeholder object.

Any help would be great.
"Moojjoo" wrote:
Ok fellow C# developers:

How do creat an instance of an object inside a dataset or datagrid.

Example I need to have a placeholder inside a dataset. Any help would be
great.

Nov 17 '05 #3
actually at run time you can access the the OnItemDataBound event of
the datalist, then use

PlaceHolder ph = (PlaceHolder)e.Item.FindControl("PlaceHolder1") (e
being the DataListItemEventArgs)

then you can access the ph as a PlaceHolder object.

be careful on PostBack, not sure if the placeholder will retain it's
state.

Nov 17 '05 #4
oh yeah, and you'll want to wrap it in a case statement

switch (e.Item.ItemType){
case ListItemType.Item: case ListItemType.AlternatingItem:
........
break;
}

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender,...
5
by: Jonathan Williams | last post by:
Hi, I have an object which inherits from WebControl (CUSTOM : WebControl) In this object I have code in which I add child contols: protected override void CreateChildControls() {...
7
by: Neo Geshel | last post by:
Greetings. I have a serious problem. I have multiple sets of tables, several of which are chained more than two tables deep. That is, I have a parent, a child, and a great-grandchild table. ...
0
by: N. Demos | last post by:
Hello, I'm having problems accessing a complex XML child node (latitude & longitude), and passing it to a function when the XML file has been read into a DataSet. Specifically, the returned object...
0
by: Rogelio Moreno | last post by:
Denis, I recommend you to bind the textbox controls to columns of your table inside your dataset, then get the bindingmanagerbase for the table, then use the position property of the...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
4
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if...
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
1
by: Bob Johnson | last post by:
..NET 3.5, Windows Forms app: My objective is to display parent/child data in two ComboBox controls, such that when a parent item is selected in one combo box, associated child items appear in the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.