本文介绍了如何将数据表分配给html的表到asp.net中的特定div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想在我的asp.net网络表单上列出1个销售信息列表。在这种情况下,我使用html的表来显示列和行。在我的表单上,我有单独的3 col(左div:宽度= 15%,中div = 70%和右div:15%)并且还有输入下拉列表的顶行,文本框作为用户要过滤的参数。 我想在中间div显示销售信息。但我不知道如何做到这一点



在编码中,我使用这样的方式将数据表分配给html表:

public void BindData()

{

gn = new general();

DataTable ds = gn.getDataTable(select cardcode ,来自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(ds.Rows中的DataRow行)

$

Response.Write();

Response.Write();

Response.Write() ;

Response.Write();

}



}

Response.Write(

CardCode CardName
+ row [cardcode]。ToString()+ + row [cardname]。ToString()+
);

}

else

{

//lblinform.Text =未找到数据。;

}

}

对于上面代码的结果,它不会向中间div显示销售信息。



有谁知道如何如上所述,将html的表格显示在中间位置?



谢谢



TONY

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

推荐答案

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



















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;
        }


    }
}


这篇关于如何将数据表分配给html的表到asp.net中的特定div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 12:54