由于其保护级别,c# 资源中的 SmtpClient 无法访问

SmtpClient in c# resource is inaccessible due to its protection level

以下 C# 源代码显示了如何使用 SmtpClient.

从我的电子邮件地址发送电子邮件
protected void btnFinal_Click(object sender, EventArgs e)
{
    SmtpClient smtpClient = new SmtpClient("xxxx");
    MailMessage mailMessagePlainText = new MailMessage();
    mailMessagePlainText.IsBodyHtml = true;
    mailMessagePlainText.BodyEncoding = Encoding.UTF8;

    mailMessagePlainText.Subject = DateTime.Now.ToString("dd-MM-yyyy");

    mailMessagePlainText.From = new MailAddress("myemail@myemail.com, ""); 

    if (count > 1)
    {
        values = value.Split(new[] { ';' }, 2);
        first = values[0];
        rest = values[1];
        mailMessagePlainText.To.Add(new MailAddress(first.ToString().Trim().ToUpper(), ""));            
    }
    else
    {
        mailMessagePlainText.To.Add(new MailAddress(second.ToString().Trim().ToUpper(), ""));
    }

    try
    {
        smtpClient.Send(mailMessagePlainText);
        Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('ok';", true);
    }
    catch (Exception ex)
    {
        throw (ex);
    }
}

现在我需要在 aspx markup

中的 Hyperlink 中使用字符串 firstsecond(我的消息的收件人)
<asp:TemplateField HeaderText="Number row"
    ItemStyle-HorizontalAlign="Center"
    ItemStyle-CssClass="ddl_Class_new"
    ItemStyle-Font-Size="Smaller"
    ItemStyle-Font-Names="Arial">
    <ItemTemplate>
        <asp:HyperLink
            ID="HyperLink1"
            runat="server"
            CssClass="ddl_Class_new"
            NavigateUrl='<%# String.Format("Default.aspx?ID={0}&TOUSER={1}", 
                             Eval("Number row").ToString(), ... ) %>'>

                            <%# Eval("Number_row") %>
        </asp:HyperLink>
    </ItemTemplate>
</asp:TemplateField>

我已经尝试过但没有成功:

NavigateUrl='<%# String.Format("Default.aspx?ID={0}&TOUSER={1}", 
                 Eval("Number row").ToString(), 
                 first.ToString().Trim().ToUpper()) %>'>

NavigateUrl='<%# String.Format("Default.aspx?ID={0}&TOUSER={1}", 
                 Eval("Number row").ToString(), 
                 second.ToString().Trim().ToUpper()) %>'>

错误是:

CS0122 first ( or second ) is inaccessible due to its protection level

有什么建议吗?

在此先感谢您的帮助

更新 #1

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        HyperLink HyperLink1 = (HyperLink)e.Row.FindControl("HyperLink1");
        HyperLink1.NavigateUrl = "Default.aspx?ID=" + DataBinder.Eval(e.Row.DataItem, "Number row").ToString() + "&TOUSER=" + first.ToString();
        HyperLink1.Text = DataBinder.Eval(e.Row.DataItem, "Number row").ToString();
    }
}

错误

Object reference not set to an instance of an object

为什么不在 Grid 的数据绑定事件后面的代码中全部设置?

 HyperLink1.NavigateURL = "default.aspx?id="+first;