我在.aspx窗体中写了调用类执行SQL语句,然后想在html中写代码把数据显示在table中,不知道如何写!初学,请大家帮帮忙!
如下是我的部分代码:
.aspx.cs:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
// lzcomputer.UserOperate.Sql_Base strconn= new lzcomputer.UserOperate.Sql_Base();
accessobj objconn = new accessobj();
SqlDataReader reader = objconn.Setnewtext();
}.cs类的代码:using System;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Xml;
using System.IO;
using System.Data.Common;
namespace lzcomputer.UserOperate
{
/// 基类
/// </summary>
public class Sql_Base
{
string strConn;
public string StrConn
{
get{return strConn;}
}
///<summary>
///构造函数没有字符串
///</summary>
public Sql_Base()
{
strConn=ConfigurationSettings.AppSettings["Connection"];
}
///<summary>
///构造函数
/// </summary>
/// <param name="strconn">连接串</param>
public Sql_Base(string strconn)
{
strConn=strconn;
}public SqlDataReader ExecuteReader(string strSql)
{
SqlDataReader objDReader=null; SqlConnection objConn=new SqlConnection (StrConn);
SqlCommand objCmd=new SqlCommand (strSql,objConn);
objConn.Open ();
objDReader=objCmd.ExecuteReader ();
//objConn.Close ();
return objDReader;
}
}
/// <summary>
/// 附件信息类
/// </summary>
public class accessobj:Sql_Base
{
private string strSql;
public SqlDataReader Setnewtext()
{
strSql="select * from newtext";
return ExecuteReader(strSql);
}
}
} 现在不知道如何在html中写在table显示的代码!
如下是我的部分代码:
.aspx.cs:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
// lzcomputer.UserOperate.Sql_Base strconn= new lzcomputer.UserOperate.Sql_Base();
accessobj objconn = new accessobj();
SqlDataReader reader = objconn.Setnewtext();
}.cs类的代码:using System;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Xml;
using System.IO;
using System.Data.Common;
namespace lzcomputer.UserOperate
{
/// 基类
/// </summary>
public class Sql_Base
{
string strConn;
public string StrConn
{
get{return strConn;}
}
///<summary>
///构造函数没有字符串
///</summary>
public Sql_Base()
{
strConn=ConfigurationSettings.AppSettings["Connection"];
}
///<summary>
///构造函数
/// </summary>
/// <param name="strconn">连接串</param>
public Sql_Base(string strconn)
{
strConn=strconn;
}public SqlDataReader ExecuteReader(string strSql)
{
SqlDataReader objDReader=null; SqlConnection objConn=new SqlConnection (StrConn);
SqlCommand objCmd=new SqlCommand (strSql,objConn);
objConn.Open ();
objDReader=objCmd.ExecuteReader ();
//objConn.Close ();
return objDReader;
}
}
/// <summary>
/// 附件信息类
/// </summary>
public class accessobj:Sql_Base
{
private string strSql;
public SqlDataReader Setnewtext()
{
strSql="select * from newtext";
return ExecuteReader(strSql);
}
}
} 现在不知道如何在html中写在table显示的代码!
解决方案 »
- Ext.net 中ComboBox绑定问题
- 帮忙写条sql语句
- 当我的网站使用了认证(win2003自代)网址变成了https,但导出不了数据了是什么原因
- vista下运行asp.net报错,请问为什么?
- 如何让程序定时执行某操作。
- 急!!!如何在Gridview里面使用checkbox?在线等!!来者有分~~多谢
- asp.net2.0是否兼容win2000+iis5.0??(这个问题不解决我就要失业了!!!!)
- bbsxp论坛的new.asp的问题
- 启动asp.net程序时提示无法在web服务器上启用调试.
- 关于隐藏控件的问题,十万火急!100分送出!!!
- Web页面上Active控件出了问题?
- 在虚拟主机上不能创建文件夹!!!???
比较常用的方法是创建Adapter,把Command赋给Adapter的SelectCommand,再调Adapter的Fill方法填充一个Table。
最后都赋给DataGrid的数据源再绑定。
再一个是用我上面调用类的方面后的实现??
我也知道可以用DataGrid来绑定,但我不想那样,郁闷呀!
2.将dataTable的值循环赋给html talbe
Ex:
1.
DataTable dt = new DataTable();
dt.Columns.Add("t1");
dt.Columns.Add("t2");
dt.Columns.Add("t3");2.将dataReader的值用dt.rows.add 给dataTable
3.传给你的table1(html table):
int curRow = 0;
int curCell = 0;
for(int i=0;i<dt.Rows.Count;i++)
{
for(int j=0;j<dt.Columns.Count;j++)
{
this.Table1.Rows[curRow].Cells[curCell].InnerText = dt.Rows[i][j].ToString(); curCell+=1;
if(curCell>2 || j==dt.Columns.Count-1)
{
curCell = 0;
curRow +=1;
} }
}
一百分相送!