DataSetToHtmlTable

2016-03-16 09:16:38  访问(2079) 赞(0) 踩(0)



///
/// DataSet转成HTML的Table输出
///

///
///
///
public static string DataSetToHtmlTable(DataSet ds, bool needConvertHTML)
{
return DataSetToHtmlTable(ds, -98, needConvertHTML);
}

///
/// DataSet转成HTML的Table输出
///

///
///
///
public static string DataSetToHtmlTable(DataSet ds,int widthValue, bool needConvertHTML)
{
if (ds == null || ds.Tables.Count == 0)
{

throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "传入参数:DataSet ds为null。"
);
}

string widthStyle = "";

if(widthValue > 0)
{
widthStyle = " width:" + widthValue.ToString() + "px;";
}
else if (widthValue < 0)
{
widthStyle = " width:" + (-widthValue).ToString() + "%;";
}

DataTable dt = ds.Tables[0];

StringBuilder theResult = new StringBuilder();

theResult.Append(@"");

if (needConvertHTML)
{
theResult.Append(@"");

foreach (DataColumn dc in dt.Columns)
{
theResult.Append(@"");

foreach (DataRow dr in dt.Rows)
{
theResult.Append(@"");

foreach (DataColumn dc in dt.Columns)
{
theResult.Append(@"");
}

theResult.Append("");
}
}
else
{
theResult.Append(@"");

foreach (DataColumn dc in dt.Columns)
{
theResult.Append(@"");
}

theResult.Append("");

foreach (DataRow dr in dt.Rows)
{
theResult.Append(@"");

foreach (DataColumn dc in dt.Columns)
{
theResult.Append(@"");
}

theResult.Append("");
}
}

theResult.Append("
");
theResult.Append(StringSlowXFunctions.ConvertHtmlTagPrefix(dc.ColumnName));

}

theResult.Append("
");
theResult.Append(StringSlowXFunctions.ConvertHtmlTagPrefix(dr[dc.ColumnName].ToString()));
theResult.Append("
");
theResult.Append(dc.ColumnName);
theResult.Append("
");
theResult.Append(dr[dc.ColumnName].ToString());
theResult.Append("
");

return theResult.ToString();
}
标签:DataSetToHtmlTable 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)