mainrotor
asked on
I need assistance with a Collection in my ASP.Net application
Hi experts,
I have a collection in my ASP.Net application with C#.Codebehind. I want to display the values
in my collection in a Label control. How can I do this? I tried the following but it gave me an error.
lblErrors.Text = validationErrors.ToString( );
Here is the code for my collection.
private Collection<String> ValidateData()
{
Collection<string> validationErrors = new Collection<String>();
if (txtTitle_Edit.Text.Length < 1)
{
validationErrors.Add("Plea se provide a title for the book.");
}
if (txtAuthorFirstname_Edit.T ext.Length < 1)
{
validationErrors.Add("Plea se enter the Author's last name.");
}
if (txtISBN_Edit.Text.Length < 1)
{
validationErrors.Add("Plea se enter the book's ISBN#.");
}
if (txtPublisher_Edit.Text.Le ngth < 1)
{
validationErrors.Add("Plea se enter the publisher's name.");
}
return validationErrors;
}
Thanks in advance
mrotor
I have a collection in my ASP.Net application with C#.Codebehind. I want to display the values
in my collection in a Label control. How can I do this? I tried the following but it gave me an error.
lblErrors.Text = validationErrors.ToString(
Here is the code for my collection.
private Collection<String> ValidateData()
{
Collection<string> validationErrors = new Collection<String>();
if (txtTitle_Edit.Text.Length
{
validationErrors.Add("Plea
}
if (txtAuthorFirstname_Edit.T
{
validationErrors.Add("Plea
}
if (txtISBN_Edit.Text.Length < 1)
{
validationErrors.Add("Plea
}
if (txtPublisher_Edit.Text.Le
{
validationErrors.Add("Plea
}
return validationErrors;
}
Thanks in advance
mrotor
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would use a generic list, convert it to an array and then use String.Join
private List<String> ValidateData()
{
List<string> validationErrors = new List<String>();
if(txtTitle_Edit.Text.Length < 1)
{
validationErrors.Add("Please provide a title for the book.");
}
if(txtAuthorFirstname_Edit.Text.Length < 1)
{
validationErrors.Add("Please enter the Author's last name.");
}
if(txtISBN_Edit.Text.Length < 1)
{
validationErrors.Add("Please enter the book's ISBN#.");
}
if(txtPublisher_Edit.Text.Length < 1)
{
validationErrors.Add("Please enter the publisher's name.");
}
return validationErrors;
}
private void button1_Click(object sender, EventArgs e)
{
lblErrors.Text = String.Join("<your seperator>", ValidateData().ToArray());
}
You need to do something like this:
Open in new window