函数调用顺序如下:    string smailto;
    string sbookname;

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
             mailto = (Label)e.Row.Controls[0].FindControl("Label10");
             bookname = (Label)e.Row.Controls[0].FindControl("Label_name");

             smailto = mailto.Text.ToString();
             sbookname = bookname.Text.ToString();
            //Label19.Text = mailto.Text;
           
        }
    }  protected void Button1_Click(object sender, EventArgs e)
    {
        
       MailAddress MessageFrom = new MailAddress("[email protected]"); //发件人邮箱地址 
        string MessageTo = "[email protected]"; //收件人邮箱地址 
        string MessageSubject =""+ smailto + "同学你好"; //邮件主题 
        string MessageBody = "您好,我通过系统得知《" + sbookname + "》在您手里,我现在急用,如果您不用了请尽快退借,给您带来的不便我深表歉意。"; //邮件内容 
        if (Send(MessageFrom, MessageTo, MessageSubject, MessageBody))
        {
            Response.Write("发送邮件成功");
        }
        else
        {
            Response.Write("发送邮件失败");
        }    }
我简单解释下,GridView1_RowDataBound已经在gridview的事件里绑定了,现在我想要gridview里label10的标签值,刚刚能获得,可是不知道怎么传递到另一个函数,所以设置两个全局变量想smailto 和 sbookname做为中介,mailto和bookname是已经定义好了的两个label,可是奇怪的事儿发生了,在GridView1_RowDataBound我设置临时label证明这时候两个变量已经有值了;可是在Button1_Click调用是发现两个值均为空,请大侠帮忙解决下,结贴加分。

解决方案 »

  1.   

    [color=#FF0000]是我刚才发帖时想设置红色字体形成的,貌似没有作用。无视吧继续请大侠帮忙!!
      

  2.   

    因为你的btn事件会发生回传  如果单单为了实现效果 可以使用ViewState来保持 数据
      

  3.   

    请问到底是什么问题?或者各位提出一个怎么将GridView1_RowDataBound中获得的值传到Button1_Click中?我的方法错在哪了?
      

  4.   

    哈哈,解决了,用session传的变量,谢谢ls的ls的兄弟了!!!