Today was a long day at work and was fighting with a DotNetNuke module. I was amazed by how C# 2.0 Anonymous functions work and was ready to implement them whenever I got a chance. So here I got a chance to do that and I went ahead…
The scenario is very simple,
How can I use anonymous functions to return the index of certain item in a dropdownlist listcontrol ?
1) My DropDownList has 4 strings
2) I have to compare *my string* with each item in the dropdownlist and if I get a string equal, I have to set that as the current index of the dropdownlist
Now I do this,
foreach(ListItem oListItem in dropdownRoles.Items)
if( oListItem.Text == “MyString” )
Just wondering can the above be accomplished by anonymous functions
I should say I was really in a bad shape. The above question is dumb ! How ?
Well, here is what I needed :D,
ListItem oListItem = dropdownRoles.Items.FindByValue(“MyString”);
if(oListItem != null)
oListItem.Selected = true;
lol, see, I was so much into this anonymous functions that I forgot .NET already had implemented a function to select a particular index whose value passed matches !
I was really feeling bad that it did not strike me at first ! 😉
Never mind, it worked, lol 😀