473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

nested datalist onItemDataBound timing confusion - help needed

I'm in a web page and I have hierarchical data so I'm using 2 nested
DataList controls.

DataList1 is using a data source with rows of [Name], [ID], [Status] and
[MoreData] where MoreData is a list.
DataList1 has an ItemTemplate with Literal controls for Name, ID and Status
and a DataList control for MoreData.

DataList2 is using MoreData where fields are [Protocol], [Domain] and
[Port].
DataList2 has an ItemTemplate with a HypeLink control.

I want to set the hyperlink's .Enabled property dependent upon the value in
Status, so when I'm binding the row in DataList 2 I need to get a handle on
the current row in DataList1.

This should be simple, right?

I searched high and low for a way to get a handle on the parent, and the
nearest I could find was a suggestion dating from 2006 where you set a
property on the page to hold a copy of the parent object. In the
OnItemDataBound event of DataList1 you set the property tot he current row,
then in the OnItemDataBound event of DataList2 you can reference the
property and all is good.

Wrong!

For some wierd reason my page is rendered out of sequence. It took me a
while to pin it down because nothing seemed to fail anywhere, but i added an
extra control to my child DataList to reveal the parent data and found what
is happening, but not why or how to fix it. Best I can do is illustrate like
this...

Name=Parent1, ID=P1, Status=Active
Protocol=http, Domain=mydomain.com, Port=80, ParentStatus=undefined,
ParentName=undefined
Protocol=http, Domain=www.mydomain.com, Port=80, ParentStatus=undefined,
ParentName=undefined
Name=Parent2, ID=P2, Status=Active
Protocol=http, Domain=otherdomain.com, Port=80, ParentStatus=Active,
ParentName=Parent1
Protocol=http, Domain=www.otherdomain.com, Port=80, ParentStatus=Active,
ParentName=Parent1
Name=Parent3, ID=P3, Status=Disabled
Protocol=http, Domain=thirdurl.com, Port=80, ParentStatus=Active,
ParentName=Parent2
Protocol=http, Domain=www.thirdurl.com, Port=80, ParentStatus=Active,
ParentName=Parent2
Name=Parent4, ID=P4, Status=Disabled
Protocol=http, Domain=fourthdomain.com, Port=80, ParentStatus=Disabled,
ParentName=Parent3
Protocol=http, Domain=www.fourthdomain.com, Port=80,
ParentStatus=Disabled, ParentName=Parent3

In the codebehind I have these lines...
public Website currentSite;

protected void DataList1_ItemDataBound(object sender,
DataListItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.AlternatingItem) ||
(e.Item.ItemType == ListItemType.Item))
{
currentSite = (Website)e.Item.DataItem;
Label l = (Label)e.Item.FindControl("StatusLabel");
if (currentSite.Status == WebsiteStatus.Started)
{
l.Text = "Started";
}
else
{
l.Text = "Not started";
}
}
}

protected void DataList2_ItemDataBound(object sender,
DataListItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.AlternatingItem) ||
(e.Item.ItemType == ListItemType.Item))
{
HyperLink h = (HyperLink)e.Item.FindControl("hLink");
h.Enabled = (currentSite.Status == WebsiteStatus.Started);
// extra debugging display labels
Label dl = (Label)e.Item.FindControl("DebugLabel");
if (currentSite.Status == WebsiteStatus.Started)
{
dl.Text = "ParentStatus=Started";
}
else
{
dl.Text = "ParentStatus=Not started";
}
dl.text += ", ParentName=" + currentSite.Name
// end of extra debugging display label code
}
}

I hope you can see from this that even though the first thing that happend
when DataList1 gets bound is that the global currentSite gets set to the
current site,
DataList2 seems to be getting bound *before* the currentSite variable is
set, but *somehow* it uses the correct list for the current site.

I'm soooo confused.

Is there a way I can control the timing of these binding events so that my
child get the proper handle on its parent?

Or is there a better way altogether of achiving my target?


Aug 29 '08 #1
0 1642

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

Similar topics

0
by: cmcilvoy | last post by:
How do i attach onitemdatabound or any event handler to a datalist nested in a repeater? /*code ***************************************************/ <asp:repeater EnableViewState="False"...
8
by: Nevyn Twyll | last post by:
I have a multi-level datalist setup: DataList1 DataList2 MyGrid I have columns explicitly defined for the grid in the html. Sometimes, On the initial Load() of the Page, I want to add extra...
1
by: Anthony | last post by:
Hi there, I have a simpletable that i have succesfully bound to a datalist.. It just shows name, description and image.. FINE.. However i would now like to simply split them into sections i.e...
8
by: bienwell | last post by:
Hi, I have a problem of displaying data bound by a datalist control. In my table, I have a field Start_date which has Short Date data type. I tried to update this field by Current Date. After...
0
by: Chris | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the...
5
by: Vikas Kumar | last post by:
i had coded like this <ItemTemplate> <table width="100%"> <tr width="100%"> <td width="25%"><%#DataBinder.Eval(Container.DataItem,"FName")%></td> <td width="25%"><input type=text ...
2
by: scottls | last post by:
Hi All, Thanks for reading my post. I have been working on getting nested datalists working properly wihtin my framework for many days and I think I'm almost there. See if you could help me...
3
by: mroffey | last post by:
Hi everyone, I've been having this problem and I've searched high and low, but I can't seem to find the answer to what is probably a very simple solution. In a nutshell, I have a nested...
1
by: terminul | last post by:
Hi I have a datalist which loops through the categories and within the datalist I have a CheckBoxList which are bound on the DataList's OnItemDataBound. The only problem I have is retrieving...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.