2017-04-25 88 views
2

我做了一个功能的代码,我上传了文件,它将被保存到数据库和文件文件夹(for filePath)中。但是当我运行并上传文件后,GridView没有出现并显示已上传的文件。我试过转向AutoGenerateColums=truedatabind(),但GridView仍然没有出现。我在这里做错了什么?Gridview没有出现

此代码是在GridView设计:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> 

这是我为我的GridView代码:

protected void bind() 
{ 
    try 
    { 
     dbconn(); 
     SqlCommand cmd = new SqlCommand("select * from ScheduleTable", con); 
     SqlDataAdapter adp = new SqlDataAdapter(cmd); 
     DataSet ds = new DataSet(); 
     adp.Fill(ds); 
     SqlDataReader rd = cmd.ExecuteReader(); 
     if (rd.Read()) 
     { 
      GridView1.DataSource = ds; 
      GridView1.DataBind(); 
     }//end if 
     else 
     { 
      ds.Tables[0].Rows.Add(ds.Tables[0].NewRow()); 
      GridView1.DataSource = ds; 
      GridView1.DataBind(); 
      int columncount = GridView1.Rows[0].Cells.Count; 
      GridView1.Rows[0].Cells.Clear(); 
      GridView1.Rows[0].Cells.Add(new TableCell()); 
      GridView1.Rows[0].Cells[0].ColumnSpan = columncount; 
      GridView1.Rows[0].Cells[0].Text = "No Record(s) Found"; 
     }//end else 
    }//end try 
    catch (Exception ex) 
    { 
     Response.Write(ex.Message); 
    }//end catch 
}//end bind() 
+0

你为什么要执行两次SQL,但只读取一次结果? – wllmsaccnt

+0

也许你的文件没有上传?首先检查表格 - 任何数据?下一步通过代码,看看你的两个(!!)记录集是否包含数据。 if的哪部分在这里运行? –

+0

作为一个评论,没有理由在你的代码中加入像'// end try'这样的注释。 – moondaisy

回答

0

你还是用这个空电网

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" EmptyDataText="No data found!">