分数都用光了。。但希望各位多帮帮忙。。非常感谢
网页里创建了
<asp:Table ID="usertable" runat="server" Width="30px">
</asp:Table>
相应的cs为:
protected void Button4_Click(object sender, EventArgs e)
{
String sql = "select * from user_info";
string[] th = { "id", "用户名", "密码" };
string[] getname = { "id", "username", "password" };
this.usertable = CreatTable.cTable(sql, th, getname);
}
调用的CreatTable类为:
public static Table cTable(string sql, string[] thname,string[] getname)
{ int col = thname.Length;
Table ct = new Table();
ct.BorderWidth = 2;
TableRow th = new TableRow();
for (int i = 0; i < col; i++)
{
TableCell thc = new TableCell();
thc.Width = 100;
thc.Text = thname[i];
th.Cells.Add(thc);
}
//取出查询的结果
DataSet ds = DB.dbSearch(sql);
if (ds.Tables[0].Rows.Count == 0)
{ }
else
{
for(int j=0;j<ds.Tables[0].Rows.Count;j++)
{
TableRow tr = new TableRow();
for (int i = 0; i < col; i++)
{
TableCell tc = new TableCell();
tc.Text = ds.Tables[0].Rows[j][getname[i]].ToString();
tc.Width = 100;
tr.Cells.Add(tc);
} ct.Rows.Add(tr); }
}
return ct; }
网页里创建了
<asp:Table ID="usertable" runat="server" Width="30px">
</asp:Table>
相应的cs为:
protected void Button4_Click(object sender, EventArgs e)
{
String sql = "select * from user_info";
string[] th = { "id", "用户名", "密码" };
string[] getname = { "id", "username", "password" };
this.usertable = CreatTable.cTable(sql, th, getname);
}
调用的CreatTable类为:
public static Table cTable(string sql, string[] thname,string[] getname)
{ int col = thname.Length;
Table ct = new Table();
ct.BorderWidth = 2;
TableRow th = new TableRow();
for (int i = 0; i < col; i++)
{
TableCell thc = new TableCell();
thc.Width = 100;
thc.Text = thname[i];
th.Cells.Add(thc);
}
//取出查询的结果
DataSet ds = DB.dbSearch(sql);
if (ds.Tables[0].Rows.Count == 0)
{ }
else
{
for(int j=0;j<ds.Tables[0].Rows.Count;j++)
{
TableRow tr = new TableRow();
for (int i = 0; i < col; i++)
{
TableCell tc = new TableCell();
tc.Text = ds.Tables[0].Rows[j][getname[i]].ToString();
tc.Width = 100;
tr.Cells.Add(tc);
} ct.Rows.Add(tr); }
}
return ct; }
var tb =document.getElementById('TableID')
for ( var i = 0 ; i < tb.rows.length; i++)
{}
但是如果不调用类里面的方法,直接把它放在按钮事件中,用<asp:table>直接添加行是可以实现的。
ct.Rows.Add(tr); 应该放到for循环中。
this.usertable = CreatTable.cTable(sql, th, getname);
</code>