如何将数据表分配给html的表到asp.net中的特定div? [英] How can i assign datatable to html's table to specific div in asp.net?

查看:50
本文介绍了如何将数据表分配给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

推荐答案

您好,



尝试使用此代码模板在运行时使用数据表数据创建动态表格...



使用asp控件创建一个下拉列表在选定的索引更改事件中从db

获取所需的过滤器数据,并将数据表分配给方法以创建新表并将其分配给div标签...







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...



.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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆