我为我上传文件的功能编写了一个代码,它将保存到数据库和文件文件夹(对于filePath)。但是当我运行并在上传文件后,GridView
没有出现并显示已经上传的文件。我尝试转向AutoGenerateColums=true
和databind()
,但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 :(得分:0)
您应该将其用于空网格
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" EmptyDataText="No data found!">