datatable 绑定数据后Count为0.。。。。。。。
代码如下:::
public partial class manage_aboutpages_Default : System.Web.UI.Page
{
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowNoticeInfo();
}
}
#region 显示所有公告信息
protected void ShowNoticeInfo()
{
dt = CommonCS.GetInfo("Notice_ShowAll");
if (dt.Rows.Count == 0)//这里正确,可以得到正常值
{
msg.Visible = true;
msg.Text = Message.RetMsg("noinfo", "");
healthist.Visible = false;
}
}
protected void delFile(int id)
{
int rowsCount = dt.Rows.Count;//这里就不行了。总是0.dt是全局变量啊。怎么为0??
//是否具有数据行
if (rowsCount>0)
{
for (int i = 0; i < rowsCount;i++ )
{
//根据id取得附件文件地址
if (id==Convert.ToInt32(dt.Rows[i]["id"]))
{
string filePath = Server.MapPath(dt.Rows[i]["filesaddress"].ToString());
//文件是否存在,存在则删除
if (System.IO.File.Exists(filePath))
{
System.IO.File.Delete(filePath);
}
}
}
}
}