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

Datalist items get the same value

8
Hi.
I'm using the following code to change a hyperlink attributes of a hyperlink which is located in an itemtemplate of a datalist.

When I debug it the attributes are changed and everything is fine, but the end result is that all of the datalist items have the same hyperlink attributes.
Somehow it goes to the last iteration of the for loop, and uses the values that are generated there.
What am I missing ? I've been working on it for two days now, so if anyone has the slightest hint ...


My code :

* SqlExecuter.GetTableCond is simply a function I use to access the database, which returns a datatable and row is a row in that datatable.

* Link and NewWindowText are columns in my database.


Expand|Select|Wrap|Line Numbers
  1. Protected Sub DataList1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataList1.PreRender
  2.         Dim newsTable As DataTable = SqlExecuter.GetTableCond("NewsTemplate", "PageId", Request.QueryString("PageId"))
  3.  
  4.         Dim row As DataRow = newsTable.Rows(newsTable.Rows.Count - 1)
  5.  
  6.         For Each item As DataListItem In DataList1.Items
  7.             Dim titleHL As HyperLink = TryCast(item.FindControl("TitleLink"), HyperLink)
  8.             titleHL.Target() = Convert.ToString(row("NewWindowText"))
  9.             If IsNumeric(Convert.ToString(row("Link"))) Then
  10.                 titleHL.NavigateUrl() = "~/Pages/PresentPage.aspx?PageId=" & Convert.ToString(row("Link"))
  11.             Else
  12.                 titleHL.NavigateUrl() = Convert.ToString(row("Link"))
  13.             End If
  14.             Dim a As String = titleHL.NavigateUrl()
  15.         Next
  16. End Sub
Nov 6 '07 #1
1 2802
nateraaaa
663 Expert 512MB
Hi.
I'm using the following code to change a hyperlink attributes of a hyperlink which is located in an itemtemplate of a datalist.

When I debug it the attributes are changed and everything is fine, but the end result is that all of the datalist items have the same hyperlink attributes.
Somehow it goes to the last iteration of the for loop, and uses the values that are generated there.
What am I missing ? I've been working on it for two days now, so if anyone has the slightest hint ...


My code :

* SqlExecuter.GetTableCond is simply a function I use to access the database, which returns a datatable and row is a row in that datatable.

* Link and NewWindowText are columns in my database.


Expand|Select|Wrap|Line Numbers
  1. Protected Sub DataList1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataList1.PreRender
  2.         Dim newsTable As DataTable = SqlExecuter.GetTableCond("NewsTemplate", "PageId", Request.QueryString("PageId"))
  3.  
  4.         Dim row As DataRow = newsTable.Rows(newsTable.Rows.Count - 1)
  5.  
  6.         For Each item As DataListItem In DataList1.Items
  7.             Dim titleHL As HyperLink = TryCast(item.FindControl("TitleLink"), HyperLink)
  8.             titleHL.Target() = Convert.ToString(row("NewWindowText"))
  9.             If IsNumeric(Convert.ToString(row("Link"))) Then
  10.                 titleHL.NavigateUrl() = "~/Pages/PresentPage.aspx?PageId=" & Convert.ToString(row("Link"))
  11.             Else
  12.                 titleHL.NavigateUrl() = Convert.ToString(row("Link"))
  13.             End If
  14.             Dim a As String = titleHL.NavigateUrl()
  15.         Next
  16. End Sub
Try moving this line
Dim row As DataRow = newsTable.Rows(newsTable.Rows.Count - 1)
to the beginning of your for each loop

For Each item As DataListItem In DataList1.Items
Dim row As DataRow = newsTable.Rows(newsTable.Rows.Count - 1)
....

Nathan
Nov 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Carl Howarth | last post by:
Hi, I have a check box list within a datalist. Can anybody tell me how I go about accessing the onclick event of these checkbox lists? (using vb.net) Many thanks, Carl Howarth...
4
by: jenn | last post by:
Hi Anyone knows how to access to a value of a row in a datalist. Something like this in datagrid Dim str = MyDataGrid.Cell(0).tex I would like something like this Dim str =...
0
by: Xiru | last post by:
I would like to retrieve the value from a DataList on postback. I can read the ItemIndex and values from a child TextBox but not cannot seem to find a way to read a databound item on the datalist....
2
by: Shiju Poyilil | last post by:
Hi ! I have a requirement wherein i am binding a datalist which contains a label (Caption for the field) and some literal hidden fields and a dropdown list. When I am binding to the datalist.....
2
by: Chris Fink | last post by:
This should be relatively simple but I am unable to find an asp:button tag in a datalist footer. I have tried it numerous ways including the FindControl method from the many events that the...
1
by: VB Programmer | last post by:
Simple: I have a datalist that is holding a bunch of job opportunities. Beside each opp (in the item template) there's a checkbox that says "apply". After the datalist there's a button that...
5
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able...
4
by: Chris Kettenbach | last post by:
Good morning all, I am sure this has been asked but I did not see anything. I have a datalist control. In the edititemtemplate I have a dropdownlist. I know on the itemdatabound event is where I...
5
by: SJ | last post by:
I have a dropdownlist("myList") in my DataList control. When a user selects one of the items in the dropdownlist, I need to access the value of the DataBound Label ("myLabel") in the Datalist and...
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...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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,...
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...

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.