【发布时间】:2011-06-11 16:39:48
【问题描述】:
我正在尝试用循环的结果填充Gridview。但我只得到循环中的最后一个结果。
我认为每次执行 for 循环时都会覆盖 GridView。
请大家帮我解决这个问题。
for (int j = 0; j < i; j++)
{
Label1.Text += fipath[j];
Label1.Text += "-------------";
SqlConnection conn = new SqlConnection("Server=ILLUMINATI;" + "Database=DB;Integrated Security= true");
SqlCommand comm = new SqlCommand("Select * from FileUpload where UploadedBy='" + NAME + "' AND FilePath='" + fipath[j] + "'", conn);
try
{
conn.Open();
SqlDataReader rdr = comm.ExecuteReader();
if (Role.Equals("admin"))
{
GridView1.DataSource = rdr;
GridView1.DataBind();
}
rdr.Close();
}
catch
{
conn.Close();
}
}
【问题讨论】:
标签: c# .net asp.net sql gridview