You must Sign In to post a response.
  • Category: ASP.NET

    How to bind the multiline textbox with comma separated values

    Dear All,

    I have a multiline textbox that has to be bound with comma separated values.
    Can anyone please suggest me or give some good links ...



    Regards,

    Raj Bangalore
  • #599346
    Hi,

    Is your requirement to set each value that is comma separated in a new line in the multiline textbox?

    - Anu

  • #599351
    Try this code:



    public static void ToCsv(Stream stream, DataTable dataTable, bool includeColumnHeaders, char valueDelimiter, char textQualifier, string rowDelimiter)
    {
    StreamWriter sw = new StreamWriter(stream);
    string valueFormatString = (textQualifier + "{0}" + textQualifier).Trim();

    if (includeColumnHeaders)
    {
    for(int i = 0; i < dataTable.Columns.Count; i++)
    {
    sw.Write(String.Format(valueFormatString, dataTable.Columns[i].ColumnName.Replace(textQualifier.ToString(), textQualifier.ToString() + textQualifier.ToString())));

    if (i != dataTable.Columns.Count - 1)
    sw.Write(valueDelimiter);
    }

    sw.Write(rowDelimiter);
    }

    for(int i = 0; i < dataTable.Rows.Count; i++)
    {
    for (int j = 0; j < dataTable.Rows[i].ItemArray.Length; j++)
    {
    sw.Write(String.Format(valueFormatString, dataTable.Rows[i][j].ToString().Replace(textQualifier.ToString(), textQualifier.ToString() + textQualifier.ToString())));

    if(j != dataTable.Rows[i].ItemArray.Length - 1)
    sw.Write(valueDelimiter);
    }
    sw.Write(rowDelimiter);
    }

    sw.Flush();
    }


    Here sample Javascript coding:

    <script language='javascript'>function frmSubmit(){ txt1 = document.getElementById("txt1").value txt2 = document.getElementById("txt2").value txt3 = document.getElementById("txt3").value location.href="NextPage.aspx?Txt1=" + txt1 + "&Txt2=" + txt2 +"&Txt3=" + txt3 }</script><input type="button" onclick="frmSubmit();" value="Submit">


    see the link:
    http://www.eggheadcafe.com/searchform.aspx?search=multiline%20textbox%20wit%20separate%20commas

    Palanikumar.A
    $-Success is often the result of taking a misstep in the right direction-$

  • #599415
    If you want all of them in Single Line then :
    StringBuilder bulder = new StringBuilder();
    string[] oldstring = { "Deb", "Shib", "Kim" };
    foreach (string str in oldstring)
    {
    bulder.Append(str);
    bulder.Append(",");
    }
    string[] newstring = bulder.ToString().Split(',');

    TextBox1.Text = bulder.ToString().TrimEnd(',');

    If you dont want them in single line :
    StringBuilder bulder = new StringBuilder();
    string[] oldstring = { "Deb", "Shib", "Kim" };
    foreach (string str in oldstring)
    {
    bulder.Append(str);
    bulder.Append(",");
    }
    string[] newstring = bulder.ToString().Split(',');
    foreach (string str1 in newstring)
    {
    TextBox1.Text += str1 + "\n";
    TextBox1.Text.Trim(',');

    }
    TextBox1.Text.Trim();

  • #599482
    Hi Debashis, Nice answer. Its working.. Thank you guys..


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.