foreach statement cannot operate on variables of type 'System.Web.UI.WebControls.Panel' because 'System.Web.UI.WebControls.Panel' does not contain a public definition for 'GetEnumerator'
The following error is where i put "?????" below.
I have image buttons in a panel and im trying to parse through each imagebutton and if its not the imagebutton you click i want to change how it appears like the border of the imagebutton
chjones2008
Member
258 Points
168 Posts
foreach ImageButton parse Cast problem
Dec 30, 2012 10:28 PM|LINK
void img_Click(object sender, ImageClickEventArgs e) { ImageButton ib = (ImageButton)sender; string imgUrl = ib.ImageUrl; MainImage.ImageUrl = imgUrl; ib.BorderColor = Color.Black; ib.BorderWidth = 3; foreach(ImageButton imgBtn in pnlImgList.?????) { if (imgBtn.ImageUrl != imgUrl) { imgBtn.BorderColor = Color.Transparent; imgBtn.BorderWidth = 0; } else { imgBtn.BorderColor = Color.Black; imgBtn.BorderWidth = 3; } } }So then i try this
foreach(ImageButton imgBtn in pnlImgList.Controls) { if (imgBtn.ImageUrl != imgUrl) { imgBtn.BorderColor = Color.Transparent; imgBtn.BorderWidth = 0; } else { imgBtn.BorderColor = Color.Black; imgBtn.BorderWidth = 3; } }and I get this error
Does anyone know what I'm suppose to put after pnlImgList. ???
oned_gk
All-Star
35710 Points
7292 Posts
Re: foreach ImageButton parse Cast problem
Dec 30, 2012 11:29 PM|LINK
Try this
foreach (Control c in pnlImgList.Controls) { if (c is ImageButton) { } }Suwandi - Non Graduate Programmer
chjones2008
Member
258 Points
168 Posts
Re: foreach ImageButton parse Cast problem
Dec 30, 2012 11:54 PM|LINK
void img_Click(object sender, ImageClickEventArgs e) { ImageButton ib = (ImageButton)sender; string imgUrl = ib.ImageUrl; string imageUrlIndex = ib.ID; MainImage.ImageUrl = imgUrl; ib.BorderColor = Color.Black; ib.BorderWidth = 3; foreach (Control c in pnlImgList.Controls) { if (c is ImageButton) { ImageButton ib2 = (ImageButton)pnlImgList.FindControl(c.ID); if (c.ID != imageUrlIndex) { ib2.BorderColor = Color.Transparent; ib2.BorderWidth = 0; } else { ib2.BorderColor = Color.Black; ib2.BorderWidth = 3; } } } }