Click here to Skip to main content
12,401,324 members (60,442 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

5.2K views
2 bookmarked
Posted

Nuts N Bolts of ASP.net

, 19 Jan 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Append New line in multiline TextBox
I had to develop a short application as an enhancement in the existing project. The application had to collect data from database and display it in gridview with CheckBoxes. The checked row data had to be sent on clipboard in row wise. To do this, I stored the strings in an array and I had to assign the string array in multiline Textbox appended by newline character. Surprisingly:

for (int i = 0; i < gvCheckboxes.Rows.Count; i++)
            {
                bool chkBoxChecked = ((CheckBox)gvCheckboxes.Rows[i].FindControl("chkBxSelect")).Checked;
                if (chkBoxChecked == true)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        _collectCellValue[j] = gvCheckboxes.Rows[i].Cells[j+1].Text.ToString();
                    }
                     _result = ConvertStringArrayToString(_collectCellValue);
                     _stringOnClipBoard[i] = _result;
        :omg: //  TextBox1.Text= _stringOnClipBoard[i]+"\r\n"   Failed to append Newline character.      
                }
             }

So I had to do as below and it did work for append newline character after each string array element Blush | :O :

foreach (string string4Clipoard in _stringOnClipBoard)
           {
               if (string4Clipoard != null)
               {
                   TextBox1.Text = TextBox1.Text + string4Clipoard + "\r\n";
               }
           }

Another issue I struggled is with Clipboard copy as the following code didn't work, God knows why, though it did work for my test work but failed on the project:

string CopyToClipboard;
CopyToClipboard = "<script type='text/javascript' language="'javascript'">function CopyToClipboard(){";
CopyToClipboard += "window.clipboardData.setData('TEXT', '" + TextBox1.Text + "');}CopyToClipboard();</script>";
Response.Write(CopyToClipboard);

So I had to use PageRegister approach as given below:

Page.RegisterStartupScript("MyScript",
                                      "<script language="javascript">" +
                                "   var Data;  Data = document.getElementById('" + TextBox1.ClientID + "').value; window.clipboardData.setData('TEXT', Data); </script>");

These are easy looking, but at times it becomes very tough to solve. Hope it becomes a time saver for someone. God help all developers. Smile | :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sanjay4India
Software Developer
India India
The Author holds degrees in Bachelor as well as Master of Computer Application. He firmly believes in the philosophy 'Sound Mind in Sound Body'. He loves Jogging, exersising and you may find him lost in deep thoughts when free.He feels Necessity is the mother of all logics and Programming can't be work but challenge whose output is fun n happiness.Bathroom is the place where he finds heaven.

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 19 Jan 2011
Article Copyright 2011 by Sanjay4India
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid