this is my row command
protected void gvResult_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Download")
{
Response.Clear();
Response.ContentType = "application/octect-stream";
Response.AppendHeader("content-disposition", "filename=" + e.CommandArgument);
Response.TransmitFile(Server.MapPath("~/Files/") + e.CommandArgument.ToString());
Response.End();
//updateCountDownloaded(e.CommandArgument.ToString());
updateCountDownloaded("1");
}
}
public void updateCountDownloaded(string iDFile)
{
files.updateCountDownloaded(iDFile);
BindTaskList();
}
and this is the files
public void updateCountDownloaded(string IdFile)
{
SqlCommand command = new SqlCommand();
command.CommandType = CommandType.Text;
command.CommandText = string.Format(
"UPDATE {0} SET Count = Count + 1 WHERE IdFile = @IdFile"
,tableName);
command.Parameters.AddWithValue("@IdFile", IdFile);
datalayer.setData(command);
}
when i try run "updateCountDownloaded("1");" in Page_load, it work properly. but why it's doesnt work in rowcommand method? how can i resolv it. thx in advance
update: no exception, no error, but my table data not updated
In your row command you are flushing the file to the response and finish excecuting further by calling Response.End. What you can try is you can call your function before excecuting the other code as below.
protected void gvResult_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Download")
{
//updateCountDownloaded(e.CommandArgument.ToString());
updateCountDownloaded("1");
Response.Clear();
Response.ContentType = "application/octect-stream";
Response.AppendHeader("content-disposition", "filename=" + e.CommandArgument);
Response.TransmitFile(Server.MapPath("~/Files/") + e.CommandArgument.ToString());
Response.End();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.