Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all experts,

I want to make 1 list of sales information on my asp.net web form. In this case, i use html's table to display column and rows. on my form, i have separate 3 col (left div: width=15%, middle div=70% and right div:15%) and also has top row to input dropdownlist,textbox as parameter for user to filter. I want sales information display in middle div. but i don't no how to do this.

In coding, i use like this for assign datatable to html's table:
public void BindData()
{
gn = new general();
DataTable ds = gn.getDataTable("select cardcode,cardname from OCRD");
if (ds.Rows.Count> 0)
{
Response.Write("");
Response.Write("");
if (ds.Rows.Count > 0)
{
//for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
foreach(DataRow row in ds.Rows)
{
Response.Write("");
Response.Write("");
Response.Write("");
Response.Write("");
}

}
Response.Write("
CardCodeCardName
" + row["cardcode"].ToString() + " " + row["cardname"].ToString() + "
");
}
else
{
//lblinform.Text = "No data found.";
}
}
For the result of the code above, it doesn't display sales information to middle div.

Does anybody know how to display html's table to middle as i mention above?

Thanks

TONY
Posted
Comments
JoCodes 29-Nov-13 2:49am    
For formatted display in a table structure you need format it using htmltable,row and columns. But always you can use a gridview control to keep it simple.

1 solution

Hi,

Try this code template for creating dynamic tables on run time using datatable data...

Create a drop down list using asp control and on the selected index change event get the desired filter data from db
and assign the data table to the method to create a new table and assign it to the div tag...



CSS
.dyngridrow {
    padding:10px;
    color:#666;
    background-color:#eeeeee;
    font-size:14px;
    border:0;
    border:2px solid #fff;
}
.dyngridrow td {
    padding:10px;
}






C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace POC
{
    public partial class WebForm2 : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {

            if (Page.IsPostBack) { }
            else
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("id", typeof(int));
                dt.Columns.Add("cardcode", typeof(string));
                dt.Columns.Add("cardname", typeof(string));
                dt.Rows.Add(1, "cc", "jjj");
                dt.Rows.Add(2, "aa", "mmmm");
                dt.Rows.Add(3, "dd", "vvv");
                dt.Rows.Add(4, "ww", "mmm");
               var table =  GenerateGrid(dt);
               divcontainer.Controls.Add(table);

            }
        }

        private Table GenerateGrid(DataTable dt)
        {
            Table tblGrid = new Table() { CellPadding = 2, CellSpacing = 2 };
            tblGrid.Style.Add("width", "100%");
            tblGrid.Style.Add("font-family", "Segoe UI");
            tblGrid.Style.Add("font-size", "14px");
            TableRow tblHeaderrow = new TableRow() { CssClass = "dyngridheaderrow" };
            tblHeaderrow.Cells.Add(new TableCell() { Text = " No" });
            tblHeaderrow.Cells.Add(new TableCell() { Text = "Card Code" });
            tblHeaderrow.Cells.Add(new TableCell() { Text = "Card Name" });

            tblGrid.Rows.Add(tblHeaderrow);
            foreach (DataRow row in dt.Rows)
            { 

                TableRow trrow = new TableRow() { CssClass = "dyngridrow" };
                
                trrow.Cells.Add(new TableCell() { Text = row["id"]+""});
                trrow.Cells.Add(new TableCell() { Text = row["cardcode"] + "" });
                trrow.Cells.Add(new TableCell() { Text = row["cardname"] + "" });

                tblGrid.Rows.Add(trrow);
            }
            return tblGrid;
        }


    }
}
 
Share this answer
 

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