Hi. I am working on a school project and I want a new line in a cell. I tried using
, \n, and Environment.NewLine but nothing works.
I have my grid code in a class:
public DataTable quoteorder(order ord, int index) //show in grid
{
DataTable table = new DataTable();
table.Columns.Add("Qty. (pieces)");
table.Columns.Add("Qty. (kilos)");
table.Columns.Add("Description");
table.Columns.Add("Print");
table.Columns.Add("Print Color");
table.Columns.Add("Hole");
table.Columns.Add("Price");
int x = 0;
//String num = "";
while (x < index)
{
//num = sale.getStockID(x);
DataRow row = table.NewRow();
row["Qty. (pieces)"] = ord.getQtypcs2(x);
row["Qty. (kilos)"] = ord.getQtykgs2(x);
row["Description"] = ord.getProdtype2(x);
row["Print"] = ord.getPrint2(x) +" - " + ord.getPrint12(x);
row["Print Color"] = ord.getPcolor2(x);
row["Hole"] = ord.getHoles2(x) + " - " + ord.getHoles12(x);
row["Price"] = ord.getPrice2(x);
table.Rows.Add(row);
x++;
}
return table;
}
Instead of having 7 columns, I want the data in the follwing columns:
table.Columns.Add("Print");
table.Columns.Add("Print Color");
table.Columns.Add("Hole");
table.Columns.Add("Price");
under the Description column. That's why I need to have a new line like this:
row["Description"] = ord.getProdtype2(x)+ NEW LINE +ord.getPrint2(x) +" - " + ord.getPrint12(x);
but I can't make
work. If I put
and run my program, it displays "
" in the grid.
The grid is called in the pageload using this code:
order.DataSource = ord.quoteorder(ord, index);
order.DataBind();
Can anyone help me on this?
Loading

sam smr4 reputationPosted Nov 5, 2009, 2:31 AM EST
//In ur html code.
//In ur c# code use
to denote line change. for ex :
string str = "Whats up?
How u doin?" ;
Dave131 reputationPosted May 18, 2008, 5:28 PM EDT
This works for me when I want to add a new line to text in a textbox.
Abby9 reputationPosted May 18, 2008, 9:45 PM EDT
Dave131 reputationPosted May 19, 2008, 5:11 AM EDT
string cellContent = ord.getProdtype2(x) + "\r\n" + ord.getPrint2(x) + " - " + ord.getPrint12(x);
row["Description"] = cellContent;
Also, note I used the escape character for the carriage return, rather than the form feed (which I previously suggested). The combination of carriage return followed by new line should work.
Abby9 reputationPosted May 19, 2008, 5:56 AM EDT
and it didn't create a new line.
Dave131 reputationPosted May 20, 2008, 3:10 AM EDT
I've never actually tried it myself, but a quick Google search turned up this tutorial.
Abby9 reputationPosted May 20, 2008, 5:09 AM EDT
i think the tutorial is for the desktop application not for the web application (ASP.net)
jarizzard7 reputationPosted May 20, 2008, 4:45 PM EDT
Abby9 reputationPosted May 22, 2008, 4:02 AM EDT
Rosie R2 reputationPosted Sep 10, 2013, 6:52 AM EDT
Template field allows you to set the data with the format that you need, you can add labels, text boxes or any other toolbox control, you can alternatively add a label and then press enter to add new line and add another label
Then in the smart tag of each label, select edit data bindings and use your own data to bind the labels.
This is the complete tutorial:
http://www.asp.net/web-forms/tutorials/data-access/custom-formatting/using-templatefields-in-the-detailsview-control-cs
Parveen SiwachRank #6,758 · 257 reputationPosted Feb 15, 2016, 9:45 AM EST
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string finalString = "Parveen
Siwach";
e.Row.Cells[0].Text = finalString;
}
}