获取变量中的页面URL并将其发送到电子邮件 [英] Get Page URL in variable and send it to Email

查看:78
本文介绍了获取变量中的页面URL并将其发送到电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我的aspx页面中有1个gridview.和1个提交按钮.

当我单击提交"按钮时,我正在生成1个ID,而该ID我想与
结合 页面URL

像这样的东西

"http://localhost:1956/GridViewEditInsert/Default.aspx?UDetailID = {0}"

现在我想将此链接通过电子邮件发送给Emial ID.

现在,当用户单击链接时,我想根据UDetailID(字段)绑定gridview.

default.aspx.cs

使用系统;
使用System.Data;
使用System.Configuration;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Web.UI.HtmlControls;
使用System.Net.Mail;
使用System.Data.SqlClient;
公共局部类_Default:System.Web.UI.Page
{
受保护的void Page_Load(对象发送者,EventArgs e)
{
字符串uid = Request.QueryString ["UDetailID"];
如果(uid!= null)
{
//字符串strSQLconnection =数据源= nikunj-29A21F8B;初始目录= HRProcess;集成安全性= True";
//SqlConnection sqlConnection =新的SqlConnection(strSQLconnection);
//SqlCommand sqlCommand =新的SqlCommand(从HRProcess_Detail中选择*,其中UDetailID =""+ uid +"'',sqlConnection);
//sqlConnection.Open();
//SqlDataAdapter adapter =新的SqlDataAdapter(sqlCommand);
//DataSet ds = new DataSet();
//adapter.Fill(ds);
/////GridView1.DataSource = ds;

//GridView1.DataBind();
}
}
//lblMessage.Text =";

受保护的void GridView1_RowUpdated(对象发送者,GridViewUpdatedEventArgs e)
{
lblMessage.Text =记录已更新";
}
受保护的void GridView1_RowDeleted(对象发送者,GridViewDeletedEventArgs e)
{
lblMessage.Text =记录已删除";
}
受保护的void GridView1_RowCommand(对象发送者,GridViewCommandEventArgs e)
{
如果(e.CommandName =="Add")
{
字符串strCName =(((TextBox)
GridView1.FooterRow.FindControl("txtCandidateName")).Text;
字符串strCNo =
((文本框)GridView1.FooterRow.FindControl
("txtContactNo")).Text;
字符串strCallTime =
((文本框)GridView1.FooterRow.FindControl
("txtCallTime")).Text;
字符串strCDate =((TextBox)GridView1.FooterRow.
FindControl("txtCallDate")).Text;
//SqlDataSource1.InsertParameters.Clear();
//SqlDataSource1.InsertParameters.Add
//("FirstName",strFirstName);
//SqlDataSource1.InsertParameters.Add
//("LastName",strLastName);
//SqlDataSource1.InsertParameters.Add
//(部门",strDepartment);
//SqlDataSource1.InsertParameters.Add
//("Location",strLocation);
SqlDataSource1.InsertParameters ["CandidateName"].DefaultValue
= strCName;
SqlDataSource1.InsertParameters ["ContactNo"].DefaultValue
= strCNo;
SqlDataSource1.InsertParameters ["CallTime"].DefaultValue
= strCallTime;
//SqlDataSource1.InsertParameters["CallDate"].DefaultValue
//= strLocation;
SqlDataSource1.Insert();
}
}
受保护的void SqlDataSource1_Inserted(对象发送者,SqlDataSourceStatusEventArgs e)
{
lblMessage.Text =已插入记录";

}
受保护的void Button1_Click(对象发送者,EventArgs e)
{
字符串网址;
url =请求.
MailMessage邮件=新的MailMessage();
mail.To.Add("chheda.nik@gmail.com");
mail.To.Add("nikunj.chheda@ymail.com");
mail.From = new MailAddress("chheda.nik@gmail.com");
mail.Subject =使用Gmail的电子邮件";
字符串正文="http://localhost:1956/GridViewEditInsert/Default.aspx?UDetailID = {0}";
mail.Body =正文;
mail.IsBodyHtml = true;
SmtpClient smtp =新的SmtpClient();
smtp.Host ="smtp.gmail.com"; //或者您的SMTP服务器地址
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials =新的System.Net.NetworkCredential("chheda.nik@gmail.com","nikunjnik");
//或者您的Smtp电子邮件ID和密码
smtp.EnableSsl = true;
smtp.Send(mail);
}
}


default.aspx

Hi I have 1 gridview in my aspx page. and 1 submit button.

when i click on submit button i m generating 1 id and that id i want to combin with
page URL

something like this

"http://localhost:1956/GridViewEditInsert/Default.aspx?UDetailID={0}"

now i want to email this link to the Emial ID.

now when user clicks on the link i want to bind gridview according to the UDetailID (Field).

default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string uid = Request.QueryString["UDetailID"];
if (uid != null)
{
// string strSQLconnection = "Data Source=nikunj-29A21F8B;Initial Catalog=HRProcess;Integrated Security=True";
// SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
// SqlCommand sqlCommand = new SqlCommand("select * from HRProcess_Detail where UDetailID=''" + uid + "''", sqlConnection);
// sqlConnection.Open();
// SqlDataAdapter adapter = new SqlDataAdapter(sqlCommand);
// DataSet ds = new DataSet();
// adapter.Fill(ds);
////GridView1.DataSource = ds;

// GridView1.DataBind() ;
}
}
//lblMessage.Text = "";

protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
lblMessage.Text = "Record Updated";
}
protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
lblMessage.Text = "Record Deleted";
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Add")
{
string strCName = ((TextBox)
GridView1.FooterRow.FindControl("txtCandidateName")).Text;
string strCNo =
((TextBox)GridView1.FooterRow.FindControl
("txtContactNo")).Text;
string strCallTime =
((TextBox)GridView1.FooterRow.FindControl
("txtCallTime")).Text;
string strCDate = ((TextBox)GridView1.FooterRow.
FindControl("txtCallDate")).Text;
//SqlDataSource1.InsertParameters.Clear();
//SqlDataSource1.InsertParameters.Add
//("FirstName", strFirstName);
//SqlDataSource1.InsertParameters.Add
//("LastName", strLastName);
//SqlDataSource1.InsertParameters.Add
//("Department", strDepartment);
//SqlDataSource1.InsertParameters.Add
//("Location", strLocation);
SqlDataSource1.InsertParameters["CandidateName"].DefaultValue
= strCName;
SqlDataSource1.InsertParameters["ContactNo"].DefaultValue
= strCNo;
SqlDataSource1.InsertParameters["CallTime"].DefaultValue
= strCallTime;
//SqlDataSource1.InsertParameters["CallDate"].DefaultValue
// = strLocation;
SqlDataSource1.Insert();
}
}
protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
lblMessage.Text = "Record Inserted";

}
protected void Button1_Click(object sender, EventArgs e)
{
string url;
url=Request.
MailMessage mail = new MailMessage();
mail.To.Add("chheda.nik@gmail.com");
mail.To.Add("nikunj.chheda@ymail.com");
mail.From = new MailAddress("chheda.nik@gmail.com");
mail.Subject = "Email using Gmail";
string Body = "http://localhost:1956/GridViewEditInsert/Default.aspx?UDetailID={0}";
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("chheda.nik@gmail.com", "nikunjnik");
//Or your Smtp Email ID and Password
smtp.EnableSsl = true;
smtp.Send(mail);
}
}


default.aspx

<%@ Page Language="C#" AutoEventWireup="true"

CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HRProcess </title>
</head>
<body>
<form id="form1" runat="server">
<div>

   <asp:GridView ID="GridView1" runat="server"

              AutoGenerateColumns="False"

              DataKeyNames="UDetailID"

              DataSourceID="SqlDataSource1"

              OnRowDeleted="GridView1_RowDeleted"

              OnRowUpdated="GridView1_RowUpdated"

              ShowFooter="true"

              OnRowCommand="GridView1_RowCommand">
<Columns>
    <asp:CommandField ShowDeleteButton="True"

                      ShowEditButton="True" />
    <asp:TemplateField HeaderText="ID" SortExpression="ID">
    <ItemTemplate>
    <asp:Label ID="lblID" runat="server"

                          Text='<%#Eval("UDetailID") %>'>
    </asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:Button ID="btnInsert" runat="server"

                Text="Insert" CommandName="Add" />
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Candidate Name">
    <ItemTemplate>
    <asp:Label ID="lblCandidateName" runat="server"

               Text='<%#Eval("CandidateName") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtCName" runat="server"

                 Text='<%#Bind("CandidateName") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="txtCandidateName" runat="server">
    </asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Contact No">
    <ItemTemplate>
    <asp:Label ID="lblCNo" runat="server"

               Text='<%#Eval("ContactNo") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtCNo" runat="server"

                 Text='<%#Bind("ContactNo") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="txtContactNo" runat="server">
    </asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="CallTime">
    <ItemTemplate>
    <asp:Label ID="lblCallTime" runat="server"

               Text='<%#Eval("CallTime") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtCTime" runat="server"

                 Text='<%#Bind("CallTime") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="txtCallTime" runat="server">
    </asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="CallDate">
    <ItemTemplate>
    <asp:Label ID="lblCallDate" runat="server"

               Text='<%#Eval("CallDate") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtCDate" runat="server"

                 Text='<%#Bind("CallDate") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="txtCallDate" runat="server">
    </asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>
</Columns>
</asp:GridView>


    <asp:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:TestDBConnectionString2 %>"

DeleteCommand="DELETE FROM [HRProcess_Detail] WHERE [UDetailID] = @UDEtailID"

InsertCommand="INSERT INTO [HRProcess_Detail] ([UDetailID],
[CandidateName],[ContactNo], [CallTime])
VALUES (@UDetailID, @CandidateName, @ContactNo, @CallTime)"

SelectCommand="SELECT [UDetailID], [CandidateName], [ContactNo],
[CallTime], [CallDate] FROM [HRProcess_Detail]"

UpdateCommand="UPDATE [HRProcess_Detail] SET
[CandidateName] = @CandidateName, [ContactNo] = @ContactNo,
[CallTime] = @CallTime, [CallDate] = @CallDate
WHERE [UDetailID] = @UDetailID" OnInserted="SqlDataSource1_Inserted">

<DeleteParameters>
    <asp:Parameter Name="UDEtailID" />
</DeleteParameters>
<UpdateParameters>
    <asp:Parameter Name="CandidateName" Type="String" />
    <asp:Parameter Name="ContactNo" Type="String" />
    <asp:Parameter Name="CallTime" Type="String" />
    <asp:Parameter Name="CallDate" Type="String" />
    <asp:Parameter Name="UDetailID" Type="String" />
</UpdateParameters>
<InsertParameters>
    <asp:Parameter Name="UDetailID" />
    <asp:Parameter Name="CandidateName" Type="String" />
    <asp:Parameter Name="ContactNo" Type="String" />
    <asp:Parameter Name="CallTime" Type="String" />
</InsertParameters>

</asp:SqlDataSource>
<asp:Label ID="lblMessage" runat="server"

           Font-Bold="True"></asp:Label><br />
    <br />
    <br />
    &nbsp;<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" /></div>
</form>
</body>
</html>




can any 1 tell me the solution for the same.. i need it urgent
thanx & Regards,




can any 1 tell me the solution for the same.. i need it urgent
thanx & Regards,

推荐答案

ConnectionStrings:TestDBConnectionString2 %>" DeleteCommand="DELETE FROM [HRProcess_Detail] WHERE [UDetailID] = @UDEtailID" InsertCommand="INSERT INTO [HRProcess_Detail] ([UDetailID], [CandidateName],[ContactNo], [CallTime]) VALUES (@UDetailID, @CandidateName, @ContactNo, @CallTime)" SelectCommand="SELECT [UDetailID], [CandidateName], [ContactNo], [CallTime], [CallDate] FROM [HRProcess_Detail]" UpdateCommand="UPDATE [HRProcess_Detail] SET [CandidateName] = @CandidateName, [ContactNo] = @ContactNo, [CallTime] = @CallTime, [CallDate] = @CallDate WHERE [UDetailID] = @UDetailID" OnInserted="SqlDataSource1_Inserted"> < DeleteParameters > <asp:Parameter Name="UDEtailID" /> < /DeleteParameters > < UpdateParameters > <asp:Parameter Name="CandidateName" Type="String" /> <asp:Parameter Name="ContactNo" Type="String" /> <asp:Parameter Name="CallTime" Type="String" /> <asp:Parameter Name="CallDate" Type="String" /> <asp:Parameter Name="UDetailID" Type="String" /> < /UpdateParameters > < InsertParameters > <asp:Parameter Name="UDetailID" /> <asp:Parameter Name="CandidateName" Type="String" /> <asp:Parameter Name="ContactNo" Type="String" /> <asp:Parameter Name="CallTime" Type="String" /> < /InsertParameters > < /asp:SqlDataSource > <asp:Label ID="lblMessage" runat="server" Font-Bold="True"></asp:Label><br /> < br > < br > &nbsp;<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" /></div> < /form > < /body > < /html >
ConnectionStrings:TestDBConnectionString2 %>" DeleteCommand="DELETE FROM [HRProcess_Detail] WHERE [UDetailID] = @UDEtailID" InsertCommand="INSERT INTO [HRProcess_Detail] ([UDetailID], [CandidateName],[ContactNo], [CallTime]) VALUES (@UDetailID, @CandidateName, @ContactNo, @CallTime)" SelectCommand="SELECT [UDetailID], [CandidateName], [ContactNo], [CallTime], [CallDate] FROM [HRProcess_Detail]" UpdateCommand="UPDATE [HRProcess_Detail] SET [CandidateName] = @CandidateName, [ContactNo] = @ContactNo, [CallTime] = @CallTime, [CallDate] = @CallDate WHERE [UDetailID] = @UDetailID" OnInserted="SqlDataSource1_Inserted"> <DeleteParameters> <asp:Parameter Name="UDEtailID" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="CandidateName" Type="String" /> <asp:Parameter Name="ContactNo" Type="String" /> <asp:Parameter Name="CallTime" Type="String" /> <asp:Parameter Name="CallDate" Type="String" /> <asp:Parameter Name="UDetailID" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="UDetailID" /> <asp:Parameter Name="CandidateName" Type="String" /> <asp:Parameter Name="ContactNo" Type="String" /> <asp:Parameter Name="CallTime" Type="String" /> </InsertParameters> </asp:SqlDataSource> <asp:Label ID="lblMessage" runat="server" Font-Bold="True"></asp:Label><br /> <br /> <br /> &nbsp;<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" /></div> </form> </body> </html>




can any 1 tell me the solution for the same.. i need it urgent
thanx & Regards,




can any 1 tell me the solution for the same.. i need it urgent
thanx & Regards,


You can use any client session management technique to pass these values on to the next page.
ViewState might be the best option for this situation.
You can use any client session management technique to pass these values on to the next page.
ViewState might be the best option for this situation.


这篇关于获取变量中的页面URL并将其发送到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆