469,338 Members | 8,424 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,338 developers. It's quick & easy.

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 2078
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Jonathan Williams | last post: by
7 posts views Thread by Neo Geshel | last post: by
reply views Thread by Rogelio Moreno | last post: by
5 posts views Thread by PAUL | last post: by
15 posts views Thread by Arpan | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
1 post views Thread by haryvincent176 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.