none
Adding Line Break To DataTable Row RRS feed

  • Question

  • For one Column of my DataTable I want to add a line break <br> if and when a ; is found.  What would be the syntax to do such?

    I add the data to my column in the DataTable like this:

    newRow["Email"] = listItem["Contact_Email_R131A"];

    Desired output is so that instead of the data reading:

    jjj111@outlook.com; eee444@outlook.com

    I want it to read

    jjj111@outlook.com;

    eee444@outlook.com


    Saturday, May 5, 2018 12:41 PM

Answers

  • Try the following

    string valueFromDataTableRow = "jjj111@outlook.com;eee444@outlook.com";
    var result = valueFromDataTableRow.Contains(";") ? 
        string.Join("<br>", valueFromDataTableRow.Split(';')) : 
        valueFromDataTableRow;
    
    MessageBox.Show(result);


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, May 5, 2018 9:33 PM
    Moderator

All replies

  • This is the C# language forum. The C# language does not recognize "<br>". Assuming you are using something that makes rows and columns in a window, we don't know what you are using.


    Sam Hobbs
    SimpleSamples.Info

    Saturday, May 5, 2018 6:10 PM
  • This is the C# language forum. The C# language does not recognize "<br>". Assuming you are using something that makes rows and columns in a window, we don't know what you are using.


    Sam Hobbs
    SimpleSamples.Info

    I am using a C# DataTable and binding the value of the column to a text box.  What I am wanting to do is simulate a <br> by "moving" the email after the ; to a secondary line.

    Saturday, May 5, 2018 6:42 PM
  • The C# language does not have DataTables and text boxes.


    Sam Hobbs
    SimpleSamples.Info

    Saturday, May 5, 2018 8:59 PM
  • Try the following

    string valueFromDataTableRow = "jjj111@outlook.com;eee444@outlook.com";
    var result = valueFromDataTableRow.Contains(";") ? 
        string.Join("<br>", valueFromDataTableRow.Split(';')) : 
        valueFromDataTableRow;
    
    MessageBox.Show(result);


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, May 5, 2018 9:33 PM
    Moderator