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
Parveen SiwachPosted Feb 15, 2016, 2:45 PM
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string finalString = "Parveen
Siwach";
e.Row.Cells[0].Text = finalString;
}
}
Rosie RPosted Sep 10, 2013, 10:52 AM
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
sam smrPosted Nov 5, 2009, 7:31 AM
//In ur html code.
//In ur c# code use
to denote line change. for ex :
string str = "Whats up?
How u doin?" ;
AbbyPosted May 22, 2008, 8:02 AM
jarizzardPosted May 20, 2008, 8:45 PM
AbbyPosted May 20, 2008, 9:09 AM
i think the tutorial is for the desktop application not for the web application (ASP.net)
DavePosted May 20, 2008, 7:10 AM
I've never actually tried it myself, but a quick Google search turned up this tutorial.
AbbyPosted May 19, 2008, 9:56 AM
and it didn't create a new line.
DavePosted May 19, 2008, 9:11 AM
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.
AbbyPosted May 19, 2008, 1:45 AM
DavePosted May 18, 2008, 9:28 PM
This works for me when I want to add a new line to text in a textbox.