Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello.. I've got problem in passing query string(unique id) to hyperlink. This hyperlink will be send as an email body for a specific recipient. The button click is function to send email that contain the hyperlink. To be more specific, the button is place inside grid view where have its own unique id and data for every row. Mean that every row in grid view will have its own send button. So when user click on the send button it will send the hyperlink that have unique id for specific row. When recipient click on the hyperlink, it will open a page that will view the data of a unique id. I hope you guys understand what I'm trying to say because I'm dying looking for an answer as I have make research on internet for a whole day and it still not solve. Please help.

What I have tried:

<asp:Button ID="sendbtn" runat="server" CommandName="Select" Text="send" />

private void SendEmail(string uniqueid)
{
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
GridView2.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
//uniqueid = GenerateRandom.GetUniqueReferalid(14);
//string cid = "tripid";
//string url = "View Transaction";
MailMessage mm = new MailMessage("adaniys93@gmail.com", "adaniys93@gmail.com");
mm.Subject = "GridView Email";
mm.Body = "<a href='http://localhost/businesstrip/PrintBusinessTrip.aspx?tripid=" + Request.QueryString["tripid"].ToString() + " > login";
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "addaniys93@gmail.com";
NetworkCred.Password = "0";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
}
}
Posted
Updated 6-Apr-17 16:24pm

1 solution

try

<asp:GridView ID="GridView1" runat="server"  OnRowCommand="GridView1_RowCommand"    >
              <Columns>
                  <asp:TemplateField> 
                      <ItemTemplate>
                          <asp:Button ID="sendbtn"  CommandArgument='<%# Eval("UniqueIDColumnName") %>'
    runat="server" CommandName="Select" Text="send" /> 
                      </ItemTemplate>
                  </asp:TemplateField>
              </Columns>
          </asp:GridView>



protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
       {
           if (e.CommandName == "Select")
           {
               var uniqueId =Convert.ToString( e.CommandArgument);
               SendEmail(uniqueId);
           }
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900