473,396 Members | 1,775 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,396 software developers and data experts.

Reading contents of DataList problem

Hi,

This one appears a little strange to me. Here is the scenario.

I load a datalist the first time a page is run. The page has a !IsPostback
and the datalist gets loaded at this point.

I have a button on the page, where I want to read the contents of the
datalist. As an example that I have found on MS...

if (MyDataList.Items.Count > 0)

{

Response.Write("The Items collection contains: " + MyDataList.Items.Count +
"<br>");

foreach(DataListItem item in MyDataList.Items)

{
Response.Write(((Label)item.Controls[0]).Text + "<br>");

}

}

Now, here is the puzzling part.

The datalist reports 7 items in the items.count. This is absolutely correct,
BUT, I cannot read any of the items.

Initially, I was trying to read it as data from the datalist. As this was
not working, I have tried setting up a hidden label with the text. (I have
made the label visible to see what is happening)

Neither of them appear to contain anything, but the return count is 7 items.

The way I am doing it is practically the same way that MS are doing it...

http://msdn2.microsoft.com/en-us/sys...ist.items.aspx

The only difference is that the data in my itemTemplate of the datalist is
inside a label control. (Incidentally, I have also tried doing
item.FindControl("LabelName") to get something out)

Any help would be appreciated.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
May 25 '06 #1
1 1561
I guess this is too difficult to answer.

In order to get me closer, I have been experimenting. I have found some
further detail that may lead someone to help me.

From the MS link in my original posting, I have written a test page that I
actually take the same data from my database. This works as expected.

I then modify the listing to put a label around the content in the datalist
(instead of it being a bound literal).

I then try reading the label with
((label)item.findcontrol("labelname")).text which then fails.

Why does having a label cause it to fail?

Any help on this would be appreciated.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"David" <da*****************@revilloc.REMOVETHIS.com> wrote in message
news:eX**************@TK2MSFTNGP02.phx.gbl...
Hi,

This one appears a little strange to me. Here is the scenario.

I load a datalist the first time a page is run. The page has a !IsPostback
and the datalist gets loaded at this point.

I have a button on the page, where I want to read the contents of the
datalist. As an example that I have found on MS...

if (MyDataList.Items.Count > 0)

{

Response.Write("The Items collection contains: " + MyDataList.Items.Count
+ "<br>");

foreach(DataListItem item in MyDataList.Items)

{
Response.Write(((Label)item.Controls[0]).Text + "<br>");

}

}

Now, here is the puzzling part.

The datalist reports 7 items in the items.count. This is absolutely
correct, BUT, I cannot read any of the items.

Initially, I was trying to read it as data from the datalist. As this was
not working, I have tried setting up a hidden label with the text. (I have
made the label visible to see what is happening)

Neither of them appear to contain anything, but the return count is 7
items.

The way I am doing it is practically the same way that MS are doing it...

http://msdn2.microsoft.com/en-us/sys...ist.items.aspx

The only difference is that the data in my itemTemplate of the datalist is
inside a label control. (Incidentally, I have also tried doing
item.FindControl("LabelName") to get something out)

Any help would be appreciated.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

May 26 '06 #2

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

Similar topics

2
by: Antonio D'Ottavio | last post by:
Good Morning, In my web page I've a datalist that is sourced by a database, the problem is that I want that one of the column of the datalist contain a dropdownbox that also is sourced by a table...
2
by: Martin Wulfe | last post by:
I want to use a connection to an existing MS Access database, but I want to be able to change which table is used to fill the datalist, using VB6, at run time by late binding the datalist to the...
4
by: V. Jenks | last post by:
What seems like a simple thing is apparently not so straightforward? I have a datalist. Inside of that datalist is an <itemtemplate> secion which contains other server controls such as a...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
4
by: bwalke | last post by:
I am developing a web form which is going to be used for manufacturing input. The form uses a DataList which list a batch of parts that may range anywhere from 1-9 parts. The DataList contains 6 ...
0
by: Alan Silver | last post by:
Hello, I'm sure this is obvious, but it's driving me mad!! I have a DataList, and I want to have the contents of each cell centred and vertically aligned to the bottom of the cell. I have tried...
6
by: Paul | last post by:
I am trying to use a DataList and the ItemTemplate. I am binding the Datalist to a SQL query that gives me a list of Items with a Parent Category. I want to loop through all the items, but...
3
by: Mirek Endys | last post by:
I have DataList as part of DataList item. DataList in DataList. The parent DataList working well including Edit command, that shows Edit template and correctly bind the data into edit template...
4
parshupooja
by: parshupooja | last post by:
Hello, I am using ASP.Net C#. I am trying to create a datalist on asp.net page. I want 3 columns: Image, Title and Description. My problem is I have tons of images in single directory based on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.