我不想將它綁定到它已被循環。我在這裏是一個上傳到gridview的csv文件。我想在它被綁定之前遍歷它。任何建議是偉大的。我想弄清楚如何循環訪問我的數據表。任何建議?
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
try
{
FileUpload1.SaveAs(Server.MapPath("") +
FileUpload1.FileName);
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
FileUpload1.PostedFile.ContentType + "<br><b>Uploaded Successfully";
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
else
{
Label1.Text = "You have not specified a file.";
}
CSVReader reader = new CSVReader(FileUpload1.PostedFile.InputStream);
string[] headers = reader.GetCSVLine();
DataTable dt = new DataTable();
foreach (string strHeader in headers)
dt.Columns.Add(strHeader);
string[] data;
while ((data = reader.GetCSVLine()) != null)
dt.Rows.Add(data);
csvReaderGv.DataSource = dt;
csvReaderGv.DataBind();
}
}
什麼阻止你執行'foreach(DataRow row in dt.Rows)...'? –
我是否在csvReaderGv.DataSource = dt之前放置它; csvReaderGv.DataBind();或之後。它的困惑正在阻止我。 – Jay
是的,因爲您的要求是:_「我想在綁定之前循環遍歷它」_。這個問題有點奇怪,不是嗎? –