开发者

Email row that has been edited in a gridview

Afternoon all.

I have a gridview that offers a line per line 'feedback' column.

Upon updating, a nice little message box says "Thanks for the feedback, we'll be in touch...etc, etc"

How would I go about grabbing this edited row of the gridview and send this to an email address?

Any help 开发者_如何转开发greatly appreciated for a c# .net novice!


I'm assuming that you have a button in that row that is being used to generate the command to send the feed back. You could set the CommandArgument on the button to "feedback" and then capture it during the onRowCommand Event.

Add the onRowCommand event in the html side of your page:

<asp:GridView ID="GridView1" runat="server" OnRowCommand="myCommand">
</asp:GridView>

Then add the event in the code behind:

protected void myCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandArgument == "feedback")
    {
        // Grab the row being edited, find the cell/control and get the text
    }
}


I actually went with the following that worked a treat:

 MailMessage feedbackmail = new MailMessage(
                "joe.bloggs@joebloggsland.co.uk",
                "joe.bloggs@joebloggsland.co.uk",
                "Subject",
                e.NewValues.Values.ToString());

            SmtpClient client = new SmtpClient("SMTP");
            try
            {
                client.Send(feedbackmail);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Email unable to be sent at this time", ex.ToString());
            }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜