函数调用顺序如下: 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调用是发现两个值均为空,请大侠帮忙解决下,结贴加分。
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调用是发现两个值均为空,请大侠帮忙解决下,结贴加分。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货