Method Question?

  • Thread starter Thread starter SouthSpawn
  • Start date Start date
S

SouthSpawn

I have the following situation.

I am creating my own user control.
This asp.net user control will have a method called "Read". When this
method is being called from the page. It will read line by line threw a
list dictionary. While reading line by line
it will be setting public properties that my page can access. So my user
control will look like this.

Usercontrol.ascx

public class clsUserControl
{
private string strMyPropertyValue;

public bool Read()
{
foreach(ListDictionary MyListRow in MyListDictionary)
{
strMyPropertyValue = (string)MyListRow.Value;
}
}

public string MyReturnedValue
{
set
{
MyReturnedValue = strMyPropertyValue;
}
}
}

Now, my webpage called webpage.aspx.
Will do the following.

public class clsMyWebPage
{
//This will reference my usercontrol on the webpage.
protected clsUserControl MyUserControl;

private void DoSomething()
{
string strGetValue;
while(MyUserControl.Read())
{
strGetValue = MyUserControl.MyReturnedValue;
}
}
}

My question is this. How do I get my ".Read" method to loop through each
row setting the public property for each new value it retrieves
from the ListDictionary? Also, meanwhile setting the .Read method to
"true" so the calling page while loop will keep looping? I hope this makes
sense.

Thanks,
Mark
 
Where oh where to begin?...

Have you ever done any programming? It looks to me like you're putting the
cart before the horse here. In this case, the cart is writing a program, and
the horse is learning to program. Without the horse, the cart is pretty much
useless.

You have a Method named "Read()" that returns a boolean value. However, it
doesn't return anything! In addition, I'm not at all sure what you expect
this function to do. As it stands, it will always assign strMyPropertyValue
the value of the last "ListDictionary" item in the "ListDictionary." The
whole loop thing is pointless.

After that, you define a Property with only a Setter, no getter. This means
that you can NEVER read the value of the property, although in one line of
code you attempt to.

IOW, this code is one big cluster-f**k.

As to your question:
My question is this. How do I get my ".Read" method to loop through each
row setting the public property for each new value it retrieves
from the ListDictionary?

That's exactly what it does. See my earlier remark.
Also, meanwhile setting the .Read method to
"true" so the calling page while loop will keep looping?

Um. No. The boolean value of the Read Method is a RETURN value. Setting it
is not something a program can do.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
Kevin,

It looks to me, as you are a typical programmer. NO PEOPLE SKILLS WHAT SO
EVER. WHILE I AM TRYING.
Another developer help me solved my problem. He at least knew how to help
people without trying to talk smack. Here is the solution I needed.

public class clsUserControl
{
IDictionaryEnumerator enumerator =
MyListDictionary.GetEnumerator();

public bool Read()
{
return enumerator.MoveNext();
}

public string MyReturnedValue
{
get
{
return enumerator.Value.ToString();
}
}
}

You might be an Microsoft MVP, and that's all you will ever be.

Mark
 
Back
Top