472,353 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 2177
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...
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...
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...
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...
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,...
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...
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...
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...
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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.