ITsolutionWizard
asked on
convert void to string in c#
The code below. I would like to convert to public string GetTextBoxValue1(Control parent)
and the return value will be finalstr
Can you show me how to change it?
and the return value will be finalstr
Can you show me how to change it?
public void GetTextBoxValue1(Control parent)
{
string str = string.Empty;
string str1 = string.Empty;
string finalstr = string.Empty;
foreach (Control x in parent.Controls)
{
if ((x.GetType() == typeof(TextBox)))
{
TextBox t = ((TextBox)(x));
//Response.Write(t.ID + " " + t.Text + "<br>");
finalstr=finalstr + "&" + t.ID + "=" + t.Text;
str = str + ("&" + t.ID + "=" + t.Text);
}
if (x.HasControls())
{
//Response.Write("NONE");
GetTextBoxValue1(x);
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
A string is not the appropriate return type for this functions
I would create a list of objects that have ID and Text attributes and add to it in each iteration
I would create a list of objects that have ID and Text attributes and add to it in each iteration
Open in new window