表格生成了,可是怎么只有最后一个单元格加了图片,各位快来抢分哪
涂大当家 2006-07-27 08:40:03 using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class table : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void cmdCreate_Click(object send,EventArgs e)
{
tbl.Controls.Clear();
int rows = Int32.Parse(TextBox1.Text);
int cols = Int32.Parse(TextBox2.Text);
TableCell cellNew = null;
Image imgNew = new Image();
imgNew.ImageUrl = "images/03.gif";
for (int row = 0; row < rows; row++)
{
TableRow rowNew = new TableRow();
tbl.Controls.Add(rowNew);
for (int col = 0; col < cols; col++)
{
cellNew = new TableCell();
cellNew.Controls.Add(imgNew);
if (chkBorder.Checked)
{
cellNew.BorderStyle = BorderStyle.Inset;
cellNew.BorderWidth = Unit.Pixel(1);
}
rowNew.Controls.Add(cellNew);
}
}
}
}
-----------------------------------------------------------------------------------------
下面的是aspx里面的内容
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="table.aspx.cs" Inherits="table" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
行:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
列:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:CheckBox ID="chkBorder" runat="server" Text="是否显示边框"/><br />
<asp:Button ID="cmdCreate" OnClick="cmdCreate_Click" runat="server" Text="OK" /><br />
<asp:Table ID="tbl" runat="server">
</asp:Table>
</div>
</form>
</body>
</html>