Reputation: 1220
I'm trying to iterate over the Style property of a control in ASP.NET. This is of type CssStyleCollection, which has a reference page on MSDN.
There is some sample code on that page for iterating through the collection and getting both the keys and values for each item in the collection. It looks like this:
IEnumerator keys = MyText.Style.Keys.GetEnumerator();
while (keys.MoveNext())
{
String key = (String)keys.Current;
dr = dt.NewRow();
dr[0] = key;
dr[1] = MyText.Style[key];
dt.Rows.Add(dr);
}
I've tried using the first line in my code, but the compiler keeps saying that I need to specify a type argument for the generic type IEnumerator. Given that I'm trying to use sample code from Microsoft itself, I'm a bit confused!
Is anyone able to help me with iterating through a CssStyleCollection?
Upvotes: 1
Views: 1170
Reputation: 6976
Try iterating like the following:
foreach (string key in MyText.Style.Keys)
{
dr = dt.NewRow();
dr[0] = key;
dr[1] = MyText.Style[key];
dt.Rows.Add(dr);
}
Upvotes: 1