2012-03-06 110 views
0

我已经写了一个代码来从数据库中获取部门并将其放入一个列表中,List<CLDepartements>;其中包含getter和setter。我怎样才能在HTML表格中显示它?我不想使用DataSet或GridView,我不使用Razor视图引擎。如何在HTML表格中显示WebService列表?

[WebMethod] 
public CLDepartements[] getAllDepartements() 
{ 
    string chConn = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString; 
    List<CLDepartements> depList = new List<CLDepartements>(); 

    using (SqlConnection conn = new SqlConnection(chConn)) 
    { 
     string sql = @"SELECT * FROM Departement"; 
     conn.Open(); 

     using(SqlCommand cmd = new SqlCommand(sql, conn)) 
     { 
      SqlDataReader rd = cmd.ExecuteReader(CommandBehavior.CloseConnection); 
      if (rd != null) 
      { 
       while (rd.Read()) 
       { 
        var dp = new CLDepartements 
        { 
         DepID = rd.GetInt32(0), 
         DepLibelle = rd.GetString(1), 
         DepDescription = rd.GetString(2) 
        }; 

        depList.Add(dp); 
       }  
      } 
     } 

     return depList.ToArray(); 
    } 
} 

回答

0

不管代码使用Web服务只需要通过返回的列表并将其输出作为在一个HTML表中的行进行迭代。

+0

谢谢CFL_Jeff。你有一个小样本或网站? – 2012-03-06 16:24:37

+0

请尝试http://social.msdn.microsoft.com/Forums/ar/biztalkgeneral/thread/6f0cadc1-7ff3-4504-99d1-a3a752ccffcc – 2012-03-06 16:32:49

+0

或http://stackoverflow.com/questions/920362/how-to-iterate - 通过-A-列表的弦 - 返回 - 从-A使用的Web服务,-jquer – 2012-03-06 16:33:13