日期:2014-05-19  浏览次数:20411 次

这段代码:datatable的,最简单的代码,请求一问题~20分表心意~
DataTable   dt=new   DataTable( "cart ");
      DataColumn   dc1=new   DataColumn( "prizename ",Type.GetType( "System.String "));
      DataColumn   dc2=new   DataColumn( "point ",Type.GetType( "System.Int16 "));
      DataColumn   dc3=new   DataColumn( "number ",Type.GetType( "System.Int16 "));
      DataColumn   dc4=new   DataColumn( "totalpoint ",Type.GetType( "System.Int64 "));
      DataColumn   dc5=new   DataColumn( "prizeid ",Type.GetType( "System.String "));
      dt.Columns.Add(dc1);
      dt.Columns.Add(dc2);
      dt.Columns.Add(dc3);
      dt.Columns.Add(dc4);
      dt.Columns.Add(dc5);

      for(int   i=0;i <10;i++)
      {
        DataRow   dr=dt.NewRow();
        dr[ "prizename "]= "&Iacute;&THORN;&Iacute;&THORN; ";
        dr[ "point "]=10;
        dr[ "number "]=1;
        dr[ "totalpoint "]=10;
        dr[ "prizeid "]= "001 ";
        dt.Rows.Add(dr);
      }


就是这段代码,本人小菜鸟一个,刚学asp.net,请问我这样写完了之后如何在前台显示出来这个数据啊?不要用绑定控件的方式,还有什么办法吗?比如 <%=xxx%> 或label或别的,只要显示数据就可以了。谢谢啊~

20分略表心意~

------解决方案--------------------
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{

CreateLabel(CreateTable());
}

}
private DataTable CreateTable()
{
DataTable dt=new DataTable( "cart ");
DataColumn dc1=new DataColumn( "prizename ",Type.GetType( "System.String "));
DataColumn dc2=new DataColumn( "point ",Type.GetType( "System.Int16 "));
DataColumn dc3=new DataColumn( "number ",Type.GetType( "System.Int16 "));
DataColumn dc4=new DataColumn( "totalpoint ",Type.GetType( "System.Int64 "));
DataColumn dc5=new DataColumn( "prizeid ",Type.GetType( "System.String "));
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
dt.Columns.Add(dc4);
dt.Columns.Add(dc5);

for(int i=0;i <10;i++)
{
DataRow dr=dt.NewRow();
dr[ "prizename "]= "&Iacute;&THORN;&Iacute;&THORN; ";
dr[ "point "]=10;
dr[ "number "]=1;
dr[ "totalpoint "]=10;
dr[ "prizeid "]= "001 ";
dt.Rows.Add(dr);
}
return dt;
}
private void CreateLabel(DataTable dt)
{
StringBuilder sb = new StringBuilder();
sb.Append( " <TABLE id= 'Table1 ' style= 'Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 8px ' cellSpacing= '1 ' cellPadding= '1 ' width= '300 ' border= '1 '> ");
for(int i = 0;i < dt.Rows.Count ; i++)
{
sb.Append( " <tr> ");
for(int j = 0 ;j < dt.Columns.Count; j ++)
{