Last post Jun 27, 2012 04:16 PM by WebAppArchitect
Jun 26, 2012 01:47 PM|WebAppArchitect|LINK
I must be missing something quite simple when it comes to working with the datalist. I am attemting to loop through the controls collection of the current datalistitem, if the control equals dropdownlist then do something. However after binding the list and
on the ItemDataBound event, the datalist says it has 0 items in the collection. However, if I look inside the DataRowView I can find the ItemArray has 20 items. So the databind was successful. Any ideas what I am doing wrong? Thanks!
Protected Sub dlEmployeeJobInfo_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlEmployeeJobInfo.ItemDataBound
If e.Item.ItemType.Equals(ListItemType.Item) Or e.Item.ItemType.Equals(ListItemType.AlternatingItem) Then
Dim item As DataListItem
For Each item In dlEmployeeJobInfo.Items
Dim x As Object = item.Controls.GetType()
Jun 26, 2012 04:33 PM|WebAppArchitect|LINK
Alright, I think I know what is going on. I'm trying to retrieve from the datalist like I would the gridview. Datalist has 1 item template, build your html as needed, no columns, hence the array of items in the gridviewROW. After playing around with it I
changed it out for a gridview. Thanks for the views!
Jun 27, 2012 03:44 PM|WebAppArchitect|LINK
I want to add the solution I ended up using on the gridview. It might someone else. My deal was trying iterate through the controls of a databound control without using find control and grab it by its type and a prefix of an id. The solution came from the
great folks at 4guysfromrolla.com.
Call from anywhere...but in my case it was on page load not ispostback and pass the control you want to recursively search through. I used gridview instead of datalist. I could have gone back to datalist I think.
Private Sub HideEditModeControls(ByRef parent As Control)
For Each c As Control In parent.Controls
If TypeOf c Is DropDownList AndAlso c.ID.Contains("ddl") Then
c.Visible = False
If TypeOf c Is TextBox AndAlso c.ID.Contains("txt") Then
c.Visible = False
If c.Controls.Count > 0 Then
Jun 27, 2012 04:16 PM|WebAppArchitect|LINK
forgot to post their link: