如何动态生成DataTable!!!!!急急 你要的需求不是DataTable了啊。是HtmlTable了吧。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 FRONTPAGE中先把这个表建好,然后把这个表的HTML代码拷下来赋给以个字符串变量,然后再Response.write(这个字符串)注意:需要把拷下来的HTML的双引号变成单引号 用xml和asp.net技术可以实现,用xml来读取和制造表格,再用asp中的readxml()方法来读取就可以了! 可以用HtmlTable生成我有一现成代码,给你参考/// <summary> /// //列表图片表,显示图片及一些信息 /// </summary> /// <param name="Count"><seealso cref="记录数"/></param> /// <param name="PicAddr"><seealso cref=""/><seealso cref="图片地址"/></param> /// <param name="StylesID"><seealso cref=""/><seealso cref="图片ID"/></param> /// <param name="ColumnCount"><seealso cref="显示列数"/></param> /// <returns></returns> public Control ListPictureTable(int Count, string[] PicAddr, int[] StylesID, int ColumnCount) { // 记录数除以列数得行数 ============= float a = (float)Count / ColumnCount; int trcount = ((int)a) + 1; if(Count % ColumnCount != 0) { trcount = ((int)a) + 1; } else { trcount = (int)a; } // ================================= //外表格开始================================================================================ HtmlTable table = new HtmlTable(); table.Attributes.Add("class", "outsideTable"); table.Align = "center"; table.Border = this.TableBorder; table.CellPadding = this.TableCellPadding; table.CellSpacing = this.TableCellSpacing; for(int i = 0; i < trcount; i ++) { HtmlTableRow tr = new HtmlTableRow(); tr.BgColor = TableRowBgColor; int r = Count%ColumnCount; int jcount = ColumnCount; if(Count > ColumnCount && Count%ColumnCount !=0 && i < trcount-1) { for(int j = 0; j < ColumnCount; j ++) { HtmlTableCell td = new HtmlTableCell(); td.Attributes.Add("class", "outsideTd"); td.Align = "center"; //内表格开始======================================================================== HtmlTable _table = new HtmlTable(); _table.Attributes.Add("class", "insideTable"); _table.Border = TableBorder; _table.CellPadding = TableCellPadding; _table.CellSpacing = TableCellSpacing; _table.BorderColor = this.bordercolor; _table.Attributes.Add("bordercolordark",this.bordercolordark); int l = i * ColumnCount + j; HtmlTableRow _tr = new HtmlTableRow(); _tr.BgColor = TableRowBgColor; HtmlTableCell _td = new HtmlTableCell(); _td.Attributes.Add("class", "insideTd"); _td.Width = Config.ThumbnailImageWidth; _td.Controls.Add(new LiteralControl("<a onclick=\"window.open('ShowShoes.aspx?StylesID='+" + StylesID[l] + ",'bailishoes','width=750,height=550,scrollbars=1')\" href=\"#\"><img src=\"" + Config.UploadPicFolder + "\\" + PicAddr[l] + "\" border=0></a>")); _td.VAlign = "middle"; _td.Align = "center"; _tr.Cells.Add(_td); _table.Rows.Add(_tr); //内表格结束======================================================================== td.Controls.Add(_table); tr.Cells.Add(td); } } else if(Count >= ColumnCount && Count % ColumnCount == 0) { for(int j = 0; j < ColumnCount; j ++) { HtmlTableCell td = new HtmlTableCell(); td.Attributes.Add("class", "outsideTd"); td.Align = "center"; //内表格开始======================================================================== HtmlTable _table = new HtmlTable(); _table.Attributes.Add("class", "insideTable"); _table.Border = TableBorder; _table.CellPadding = TableCellPadding; _table.CellSpacing = TableCellSpacing; _table.BorderColor = this.bordercolor; _table.Attributes.Add("bordercolordark",this.bordercolordark); int l = i * ColumnCount + j; HtmlTableRow _tr = new HtmlTableRow(); _tr.BgColor = TableRowBgColor; HtmlTableCell _td = new HtmlTableCell(); _td.Attributes.Add("class", "insideTd"); _td.Width = Config.ThumbnailImageWidth; _td.Controls.Add(new LiteralControl("<a onclick=\"window.open('ShowShoes.aspx?StylesID='+" + StylesID[l] + ",'bailishoes','width=750,height=550,scrollbars=1')\" href=\"#\"><img src=\"" + Config.UploadPicFolder + "\\" + PicAddr[l] + "\" border=0></a>")); _td.VAlign = "middle"; _td.Align = "center"; _tr.Cells.Add(_td); _table.Rows.Add(_tr); //内表格结束======================================================================== td.Controls.Add(_table); tr.Cells.Add(td); } } else if(Count%ColumnCount !=0 && i == trcount-1) { //如果不等于0时 jcount = r; for(int j = 0; j < jcount; j ++) { HtmlTableCell td = new HtmlTableCell(); td.Attributes.Add("class", "outsideTd"); td.Align = "center"; //内表格开始======================================================================== HtmlTable _table = new HtmlTable(); _table.Attributes.Add("class", "insideTable"); _table.Border = TableBorder; _table.CellPadding = TableCellPadding; _table.CellSpacing = TableCellSpacing; _table.BorderColor = this.bordercolor; _table.Attributes.Add("bordercolordark",this.bordercolordark); int l = i * ColumnCount + j; HtmlTableRow _tr = new HtmlTableRow(); _tr.BgColor = TableRowBgColor; HtmlTableCell _td = new HtmlTableCell(); _td.Attributes.Add("class", "insideTd"); _td.Width = Config.ThumbnailImageWidth; _td.Controls.Add(new LiteralControl("<a onclick=\"window.open('ShowShoes.aspx?StylesID='+" + StylesID[l] + ",'bailishoes','width=750,height=550,scrollbars=1')\" href=\"#\"><img src=\"" + Config.UploadPicFolder + "\\" + PicAddr[l] + "\" border=0></a>")); _td.VAlign = "middle"; _td.Align = "center"; _tr.Cells.Add(_td); _table.Rows.Add(_tr); //内表格结束======================================================================== td.Controls.Add(_table); tr.Cells.Add(td); } } table.Rows.Add(tr); } //====================================================================================== //外表格结束================================================================================ return table; } 1、先用frontpage或者VS.NET等工具画出你的Table!2、打开HTML部分。3、在CS里面着手写代码,使用HtmlTable或者Table都可以,用到以下对象HtmlRow(Row),HtmlCell(Cell),和他们的属性(ColSpan和RowSpan等)。具体代码就不写了! 我需要的就是你说的HtmlTable,让我来试试看,我所说的只是一部分而已 分页非常好分页,你用一个分页控件,使用分页控件返回一个的DataSet再用这个DataSet填充到你要的表中。 这种动态生成得表格不太适合有分页控件,我是在动态生成表格的同时,根据表中的数据动态生成LinkButton,由LinkButton来控制分页,我曾用过一个分页控件HxDataPage但是不太好实现! cuike519(Knowledge is Power) 老兄!你所说的是不是事先用frontpage画好表格把它html中的table代码复制的cs的程序中,通过程序来实现表格,但是这样的表格存在一个问题就是表格的位置不好确定,再者说我这个表是一个二维表,横向、纵向的变化是一个不确定的值, 可以说我这个是一个旬计划,横向是根据上、中、下旬的天数来确定的,而纵向是根据记录来确定的 在第一列中由三行合并为一行、第二列是三行确定的内容,后面的就是不确定的内容了是要根据记录数来实现了总的来说是很复杂的不知老兄有何见解呢? google个性化桌面实现??????????????????????????【标题要长】 求助 哪位高手知道在c#里读取图片的格式信息(如gif图片的颜色值,帧数等) 类型转换为日期的问题 请问怎样在自定义控件中访问该控件所在页面的其他服务器控件? 为什么页面不能在指定的框架内显示。(treeview) GridView分页问题,有多个DataSet对象时 如何利用aspx页面发送邮件? 数组怎样保存在web页面 如果快速多次调用远程接口 讨论:这么多功能的网上相簿是如何实现的? 如何获得控件坐标
Response.write(这个字符串)
注意:需要把拷下来的HTML的双引号变成单引号
我有一现成代码,给你参考
/// <summary>
/// //列表图片表,显示图片及一些信息
/// </summary>
/// <param name="Count"><seealso cref="记录数"/></param>
/// <param name="PicAddr"><seealso cref=""/><seealso cref="图片地址"/></param>
/// <param name="StylesID"><seealso cref=""/><seealso cref="图片ID"/></param>
/// <param name="ColumnCount"><seealso cref="显示列数"/></param>
/// <returns></returns>
public Control ListPictureTable(int Count, string[] PicAddr, int[] StylesID, int ColumnCount)
{
// 记录数除以列数得行数 =============
float a = (float)Count / ColumnCount;
int trcount = ((int)a) + 1;
if(Count % ColumnCount != 0)
{
trcount = ((int)a) + 1;
}
else
{
trcount = (int)a;
}
// =================================
//外表格开始================================================================================
HtmlTable table = new HtmlTable();
table.Attributes.Add("class", "outsideTable");
table.Align = "center";
table.Border = this.TableBorder;
table.CellPadding = this.TableCellPadding;
table.CellSpacing = this.TableCellSpacing;
for(int i = 0; i < trcount; i ++)
{
HtmlTableRow tr = new HtmlTableRow();
tr.BgColor = TableRowBgColor;
int r = Count%ColumnCount;
int jcount = ColumnCount; if(Count > ColumnCount && Count%ColumnCount !=0 && i < trcount-1)
{
for(int j = 0; j < ColumnCount; j ++)
{
HtmlTableCell td = new HtmlTableCell();
td.Attributes.Add("class", "outsideTd");
td.Align = "center"; //内表格开始========================================================================
HtmlTable _table = new HtmlTable();
_table.Attributes.Add("class", "insideTable");
_table.Border = TableBorder;
_table.CellPadding = TableCellPadding;
_table.CellSpacing = TableCellSpacing;
_table.BorderColor = this.bordercolor;
_table.Attributes.Add("bordercolordark",this.bordercolordark);
int l = i * ColumnCount + j;
HtmlTableRow _tr = new HtmlTableRow();
_tr.BgColor = TableRowBgColor;
HtmlTableCell _td = new HtmlTableCell();
_td.Attributes.Add("class", "insideTd");
_td.Width = Config.ThumbnailImageWidth;
_td.Controls.Add(new LiteralControl("<a onclick=\"window.open('ShowShoes.aspx?StylesID='+" + StylesID[l] + ",'bailishoes','width=750,height=550,scrollbars=1')\" href=\"#\"><img src=\"" + Config.UploadPicFolder + "\\" + PicAddr[l] + "\" border=0></a>"));
_td.VAlign = "middle";
_td.Align = "center";
_tr.Cells.Add(_td);
_table.Rows.Add(_tr); //内表格结束========================================================================
td.Controls.Add(_table);
tr.Cells.Add(td);
}
}
else if(Count >= ColumnCount && Count % ColumnCount == 0)
{
for(int j = 0; j < ColumnCount; j ++)
{
HtmlTableCell td = new HtmlTableCell();
td.Attributes.Add("class", "outsideTd");
td.Align = "center"; //内表格开始========================================================================
HtmlTable _table = new HtmlTable();
_table.Attributes.Add("class", "insideTable");
_table.Border = TableBorder;
_table.CellPadding = TableCellPadding;
_table.CellSpacing = TableCellSpacing;
_table.BorderColor = this.bordercolor;
_table.Attributes.Add("bordercolordark",this.bordercolordark);
int l = i * ColumnCount + j;
HtmlTableRow _tr = new HtmlTableRow();
_tr.BgColor = TableRowBgColor;
HtmlTableCell _td = new HtmlTableCell();
_td.Attributes.Add("class", "insideTd");
_td.Width = Config.ThumbnailImageWidth;
_td.Controls.Add(new LiteralControl("<a onclick=\"window.open('ShowShoes.aspx?StylesID='+" + StylesID[l] + ",'bailishoes','width=750,height=550,scrollbars=1')\" href=\"#\"><img src=\"" + Config.UploadPicFolder + "\\" + PicAddr[l] + "\" border=0></a>"));
_td.VAlign = "middle";
_td.Align = "center";
_tr.Cells.Add(_td);
_table.Rows.Add(_tr);
//内表格结束========================================================================
td.Controls.Add(_table);
tr.Cells.Add(td);
}
}
else if(Count%ColumnCount !=0 && i == trcount-1)
{
//如果不等于0时
jcount = r;
for(int j = 0; j < jcount; j ++)
{
HtmlTableCell td = new HtmlTableCell();
td.Attributes.Add("class", "outsideTd");
td.Align = "center"; //内表格开始========================================================================
HtmlTable _table = new HtmlTable();
_table.Attributes.Add("class", "insideTable");
_table.Border = TableBorder;
_table.CellPadding = TableCellPadding;
_table.CellSpacing = TableCellSpacing;
_table.BorderColor = this.bordercolor;
_table.Attributes.Add("bordercolordark",this.bordercolordark);
int l = i * ColumnCount + j;
HtmlTableRow _tr = new HtmlTableRow();
_tr.BgColor = TableRowBgColor;
HtmlTableCell _td = new HtmlTableCell();
_td.Attributes.Add("class", "insideTd");
_td.Width = Config.ThumbnailImageWidth;
_td.Controls.Add(new LiteralControl("<a onclick=\"window.open('ShowShoes.aspx?StylesID='+" + StylesID[l] + ",'bailishoes','width=750,height=550,scrollbars=1')\" href=\"#\"><img src=\"" + Config.UploadPicFolder + "\\" + PicAddr[l] + "\" border=0></a>"));
_td.VAlign = "middle";
_td.Align = "center";
_tr.Cells.Add(_td);
_table.Rows.Add(_tr);
//内表格结束========================================================================
td.Controls.Add(_table);
tr.Cells.Add(td);
}
}
table.Rows.Add(tr);
}
//======================================================================================
//外表格结束================================================================================
return table;
}
2、打开HTML部分。
3、在CS里面着手写代码,使用HtmlTable或者Table都可以,用到以下对象HtmlRow(Row),HtmlCell(Cell),和他们的属性(ColSpan和RowSpan等)。具体代码就不写了!
你用一个分页控件,使用分页控件返回一个的DataSet再用这个DataSet填充到你要的表中。
老兄!你所说的是不是事先用frontpage画好表格把它html中的table代码复制的cs的程序中,通过程序来实现表格,但是这样的表格存在一个问题就是表格的位置不好确定,再者说我这个表是一个二维表,横向、纵向的变化是一个不确定的值,
可以说我这个是一个旬计划,横向是根据上、中、下旬的天数来确定的,而纵向是根据记录来确定的 在第一列中由三行合并为一行、第二列是三行确定的内容,后面的就是不确定的内容了是要根据记录数来实现了总的来说是很复杂的
不知老兄有何见解呢?