Click here to Skip to main content
15,888,287 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello...
I want to display data in aspx page like this format.
Product Name	Mobile				
Qty Rate:	100				
Unit Rate:	125				
  
       A1	A2	A3	A4	Total
Red	10	20	30	40	100
Blue	10	20	30	40	100
Green  10	20	30	40	100
				         Total	300
Product Name	Car				
Qty Rate:	120				
Unit Rate:	150
       B1	B2	B3	B4	Total
Red	10	20	30	40	100
Blue	10	20	30	40	100
Green  10	20	30	40	100
				         Total	300
				   Grand Total:	600

I have one datatable with this value.
I want to display in page but i have't any idea about which control should i use?
Plz Help...
Posted
Updated 27-Nov-11 19:26pm
v2
Comments
[no name] 25-Nov-11 23:45pm    
You can use a number of controls, the choice really up to you and the requirements of the project
Sergey Alexandrovich Kryukov 26-Nov-11 0:18am    
Not a question. What's the problem?
--SA

are those data static? if it is, use a simple html table. if not, create a table specific custom forms. Here, for your reference:

http://weblogs.asp.net/nannettethacker/archive/2008/01/24/html-tables-to-asp-net-table-controls.aspx[^]

http://www.asp.net/aspnet-in-net-35-sp1/videos/how-to-create-table-specific-custom-forms-in-an-aspnet-dynamic-data-application[^]

Best regards,
Eduard
 
Share this answer
 
Quote:
I have one datatable with this value.

I wonder how would you have all these details in one DataTable. Anyways, you may try to do this by using "Nested GridViews". I am not too sure about nesting of other Data-Listing controls like Repeater Control etc.

Here are few CodeProject Articles on this.
Editable Nested GridView (All-in-One)

Gridview inside Gridview in ASP.NET C#

Gridview Inside a GridView in ASP.NET 2.0
 
Share this answer
 
I this this will be solve the above Problem...

//Code Behind File Write one Function and Call it in Page Load...
public void getTable()
    {
        Table table = new Table();

        table.ID = "Table1";
        table.BorderStyle = BorderStyle.Solid;
        Page.Form.Controls.Add(table);

        // Now iterate through the table and add your controls
        int totRow = 2;
        int totCol = 4;
        for (int i = 0; i < totRow; i++)
        {

            TableRow row = new TableRow();

            for (int j = 0; j < totCol; j++)
            {

                TableCell cell = new TableCell();

                TextBox tb = new TextBox();

                // Set a unique ID for each TextBox added

                tb.ID = "TextBoxRow_" + i + "Col_" + j;
                tb.Attributes.Add("runat", "Server");
                tb.Attributes.Add("OnFocusOut", "processText()");
                //tb.EnableViewState = false;
                tb.MaxLength = 128;

                HiddenField hf = new HiddenField();
                hf.ID = "HF_" + i + "Col_" + j;
                hf.Value = (10 * (i+1)).ToString();
                cell.Controls.Add(hf);
                cell.Controls.Add(tb);

                // Add the TableCell to the TableRow

                row.Cells.Add(cell);

            }
            TableCell celltot = new TableCell();
            TextBox tbTot = new TextBox();
            
            tbTot.ID = "TotalRow_" + i + "Col_" + (totCol).ToString();
           // tbTot.Attributes.Add("runat", "Server");
            //tbTot.Attributes.Add("OnFocusOut", "processText()");
            //tbTot.EnableViewState = false;
            tbTot.MaxLength = 128;
            tbTot.ReadOnly = true;
            
            celltot.Controls.Add(tbTot);
            row.Cells.Add(celltot);
            // Add the TableRow to the Table
            table.Rows.Add(row);
        }

        TableRow Grow = new TableRow();
        Grow.HorizontalAlign = HorizontalAlign.Right;
        TableCell Gcelltot = new TableCell();
        Label lbl = new Label();
        lbl.Text = "Total: ";
        Gcelltot.Controls.Add(lbl);
        
        TextBox GtbTot = new TextBox();
        Gcelltot.ColumnSpan = 5;
        GtbTot.ID = "GTotal";
        GtbTot.MaxLength = 128;
        GtbTot.ReadOnly = true;

        Gcelltot.Controls.Add(GtbTot);
        Grow.Cells.Add(Gcelltot);
        // Add the Gcelltot to the Table
        table.Rows.Add(Grow);

    }


// Create Java Script Like
function processText() {
      var Gtotal = 0;
      var totRows = document.getElementById("Table1").rows.length;
      for (var i = 0; i < totRows; i++) {
          if (i == totRows - 1) {
              TBox = document.getElementById("GTotal");
              TBox.value = Gtotal;
          }
          else {
              var totCol = document.getElementById("Table1").rows[i].cells.length
              var total = 0;
              for (var j = 0; j < totCol; j++) {
                  if (j == totCol - 1) {
                      TBox = document.getElementById("TotalRow_" + i + "Col_" + (totCol - 1));
                      TBox.value = total;
                      Gtotal = Gtotal + total;
                  }
                  else {
                      HBox = document.getElementById("HF_" + i + "Col_" + j);
                      var hdata = parseFloat(HBox.value);

                      if (hdata != null && hdata != "") {
                          TBox = document.getElementById("TextBoxRow_" + i + "Col_" + j);

                          var data = TBox.value;
                          if (data != null && data != "") {
                              total = total + (hdata * parseFloat(data));
                          }
                      }
                  }
              }
          }
      }
  }
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900