我要实现的操作是:点击下载后下载指定文件,按钮变成“确定”,出现隐藏的列TextBox,点击确定以后,执行数据插入操作。
现在的问题是:当执行下载操作后,我给Button赋的值由变回来了
第二个IF语句并不执行,请大家帮帮忙,帮我实现这个功能,谢谢。没分了,和大家交个朋友。
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string T_id = Session["Username"].ToString();
string CourseName = DropDownList1.SelectedValue;
string ClassName = DropDownList2.SelectedValue;
int Degree = Convert.ToInt32(DropDownList3.SelectedValue);
BLL.Work.Teacher.Homework BWTH = new BLL.Work.Teacher.Homework();
DataSet ds = BWTH.GetStudent(T_id, Degree, CourseName, ClassName);
int index = Convert.ToInt32(e.CommandArgument);
string path =Server.MapPath(ds.Tables["StudentWorkList"].Rows[index][8].ToString());
if (e.CommandName == "downfile")
{
GridView1.Columns[1].Visible = true;
Button BT = (Button)GridView1.Rows[index].FindControl("Button2");
//给Button属性重新赋值
BT.Text = "确定";
BT.CommandName = "fraction";
//下载操作
Response.Clear();
Response.Buffer = true;
Response.Charset = "UTF-8";
Response.AddHeader("Content-Disposition", "attachment");
FileInfo aFile = new FileInfo(path); this.Page.Response.Clear();
this.Page.Response.ClearHeaders();
this.Page.Response.BufferOutput = false; this.Page.Response.ContentType = "application/octet-stream";
this.Page.Response.AppendHeader("Content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(aFile.Name, Encoding.UTF8));
this.Page.Response.AddHeader("Content-Length", aFile.Length.ToString()); this.Page.Response.WriteFile(aFile.FullName);
this.Page.Response.Flush();
this.Page.Response.End(); }
//不执行???????????
if (e.CommandName == "fraction")
{
TextBox TB = (TextBox)GridView1.Rows[index].FindControl("TextBox1");
string Mark = TB.Text.Trim();
string sno = ds.Tables["StudentWorkList"].Rows[index][3].ToString();
//插入数据操作
InsertFraction(sno, T_id, CourseName, Degree, Mark);
}
}
现在的问题是:当执行下载操作后,我给Button赋的值由变回来了
第二个IF语句并不执行,请大家帮帮忙,帮我实现这个功能,谢谢。没分了,和大家交个朋友。
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string T_id = Session["Username"].ToString();
string CourseName = DropDownList1.SelectedValue;
string ClassName = DropDownList2.SelectedValue;
int Degree = Convert.ToInt32(DropDownList3.SelectedValue);
BLL.Work.Teacher.Homework BWTH = new BLL.Work.Teacher.Homework();
DataSet ds = BWTH.GetStudent(T_id, Degree, CourseName, ClassName);
int index = Convert.ToInt32(e.CommandArgument);
string path =Server.MapPath(ds.Tables["StudentWorkList"].Rows[index][8].ToString());
if (e.CommandName == "downfile")
{
GridView1.Columns[1].Visible = true;
Button BT = (Button)GridView1.Rows[index].FindControl("Button2");
//给Button属性重新赋值
BT.Text = "确定";
BT.CommandName = "fraction";
//下载操作
Response.Clear();
Response.Buffer = true;
Response.Charset = "UTF-8";
Response.AddHeader("Content-Disposition", "attachment");
FileInfo aFile = new FileInfo(path); this.Page.Response.Clear();
this.Page.Response.ClearHeaders();
this.Page.Response.BufferOutput = false; this.Page.Response.ContentType = "application/octet-stream";
this.Page.Response.AppendHeader("Content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(aFile.Name, Encoding.UTF8));
this.Page.Response.AddHeader("Content-Length", aFile.Length.ToString()); this.Page.Response.WriteFile(aFile.FullName);
this.Page.Response.Flush();
this.Page.Response.End(); }
//不执行???????????
if (e.CommandName == "fraction")
{
TextBox TB = (TextBox)GridView1.Rows[index].FindControl("TextBox1");
string Mark = TB.Text.Trim();
string sno = ds.Tables["StudentWorkList"].Rows[index][3].ToString();
//插入数据操作
InsertFraction(sno, T_id, CourseName, Degree, Mark);
}
}
先插数据到数据库,再下载2. 如果非要按照现有的逻辑:
实际上第二个if是没有用的,我这里就假设你这里必须有这个if(1)先把button的text和commond name存到一个session里,然后
当页面刷新的时候,从session里重新绑定btn的这些属性。