Ah..How did I forget this !

23 08 2007

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 ?

For example,

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 😀




One response

23 08 2007
David Xie

thanks for the tips 😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: