11
Answers

New Line in GridView cell

Abby

Abby

8y
31.5k
1
Hi. I am working on a school project and I want a new line in a cell. I tried using <br>, \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 <br> work. If I put <br> and run my program, it displays "<br>" 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?
Answers (11)