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

50分请高手救命啦!用DataTable显示一个字段的值为什么没显示数据呢?
string   Field     = "20070410145513339.jpg20070410145516857.jpg20070410145520925.jpg ";  
string[]   AllImg   =   Field.Split( '| ');  
DataTable   T   =   new   DataTable();
T.Columns.Add( "ImgUrl ",Type.GetType( "System.String "));
DataRow   dr   =   T.NewRow();
 
foreach(string   PerImg   in   AllImg)
{
Response.Write(PerImg);
dr[ "ImgUrl "]   =   PerImg;
}

T.Rows.Add(dr);
List.DataSource   =   T;
List.DataBind();

------解决方案--------------------
string Field = "20070410145513339.jpg|20070410145516857.jpg|20070410145520925.jpg ";
string[] AllImg = Field.Split( '| ');
DataTable T = new DataTable();
T.Columns.Add( "ImgUrl ",Type.GetType( "System.String "));
DataRow dr;
foreach(string PerImg in AllImg)
{
dr = T.NewRow();
Response.Write(PerImg);
dr[ "ImgUrl "] = PerImg;
T.Rows.Add(dr);
}
List.DataSource = T;
List.DataBind();

前台绑定数据 <%# DataBinder.Eval(Container.DataItem, "ImgUrl ")%>
------解决方案--------------------
string Field = "20070410145513339.jpg20070410145516857.jpg20070410145520925.jpg ";
string[] AllImg = Field.Split( '| ');
这样儿得出来的AllImg是null的,你在拼字符串的时候,要加分隔字符的
string Field = "20070410145513339.jpg|20070410145516857.jpg|20070410145520925.jpg ";
string[] AllImg = Field.Split( '| ');
这样儿AllImg才有内容的,再放到DataTable里才有内容的嘛