我要实现的操作是:点击下载后下载指定文件,按钮变成“确定”,出现隐藏的列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);
            }
        }

解决方案 »

  1.   

    如果e.CommandName == "downfile"只会执行第一个if,因为e.CommandName不能是"fraction"了
      

  2.   

    不好 意思,没看清楚.到第二个if前e.CommandName还是不变的,是"down",所以第二个if里的内容不执行
      

  3.   

    你这个判断没有什么实际意义呀~~!! 先设置了BT.CommandName = "fraction";........然后又判断if (e.CommandName == "fraction") 这有意义么? 我觉得它不执行进去还真是奇迹 !!直接不要判断就行了!
      

  4.   

    下载的时候就跳出了,没有执行到第二个IF,直接就刷新了一次页面,然后又页面重载一次,所以第二个IF始终得不到执行。现在就是想怎么样又能下载,页面又不重载一次,或者重载后使Button1的e.CommandName值还使变成BT.CommandName = "fraction";进而第二次点击的时候执行第二个IF
      

  5.   

    1. 改逻辑:
     先插数据到数据库,再下载2. 如果非要按照现有的逻辑:
     实际上第二个if是没有用的,我这里就假设你这里必须有这个if(1)先把button的text和commond name存到一个session里,然后
     当页面刷新的时候,从session里重新绑定btn的这些属性。