你可以先用ds.Tables["XXX"].Rows.Count判断有多少行

解决方案 »

  1.   

    是可以判断有多少纪录 但是我如何赋值呢?
    我现在是硬编码的,直接
    Img1.ImgUrl = ds.Tables["XXX"].Rows[0]["PicPathField"].ToString();
    Img2.ImgUrl = ds.Tables["XXX"].Rows[1]["PicPathField"].ToString();
    ...
    Img9.ImgUrl = ds.Tables["XXX"].Rows[8]["PicPathField"].ToString();
    我想用for循环来赋值的,大概思路如下
    for (int i=0;i<9;i++)

        (Img+i).ImgUrl =ds.Tables["XXX"].Rows[i]["PicPathField"].ToString(); 
    }但是 (Img+i) 就会被认为是字符串 不再是图片Img1或这Img2了 请问有没有什么解决方法? 或者有没有什么更好的思路或实现方法呢?
      

  2.   

    其实可以用DataList实现,就不用那么麻烦了。
      

  3.   

    int li_count=9;
    if (ds.Tables["XXX"].Rows.Count < 9 ) li_count = ds.Tables["XXX"].Rows.Count ;
    for (int i=0;i< li_count;i++)

        (Img+i).ImgUrl =ds.Tables["XXX"].Rows[i]["PicPathField"].ToString(); 
    }
      

  4.   

    但是 (Img+i) 就会被认为是字符串 不再是图片Img1或这Img2了 请问有没有什么解决方法? 或者有没有什么更好的思路或实现方法呢?可以直接写
    string ls_show="";
    for (int i=0;i< li_count;i++)

        ls_show+="<IMG img"+i+".src="+ds.Tables["XXX"].Rows[i]["PicPathField"].ToString()+"><br>"; 
    }
    Response.Write(ls_show);
      

  5.   

    介绍你看过漂亮的:http://www.iisworks.com/listpics/home.asp