我已经制作了listview,我从中获取了客户的电子邮件ID。有从所选列发送邮件的按钮。我不知道怎么做,请帮助我。这是我现在正在处理的代码..
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class dashboard
Inherits System.Web.UI.Page
Dim con As New SqlConnection("Data Source=SuRaj;Initial Catalog=Brandstik2; Integrated Security=True")
Dim Comp_ID, client_name As String
Protected Sub add_company_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles add_company.Click
add_client.Visible = True
headings.Text = "Add New Companies"
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindListView()
End If
add_client.Visible = False
send_request_form.Visible = False
headings.Text = "Dashboard"
'Dim str1 As String = "Select * from BrandstikTesti"
'Dim cmd1 As New SqlCommand(str1, con)
'con.Open()
'Dim rdr1 As SqlDataReader = cmd1.ExecuteReader
'While rdr1.Read
' Label1.Text = rdr1(0)
' Label2.Text = rdr1(1)
'End While
'con.Close()
'rdr1.Close()
'cmd1.Dispose()
End Sub
Protected Sub send_request_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles send_request.Click
add_client.Visible = False
send_request_form.Visible = True
headings.Text = "Send Feedback Request"
success.Visible = False
End Sub
Protected Sub submit_client_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit_client.Click
Dim Comp_ID, client_name, email_id As String
form1.Visible = True
Comp_ID = TextBox1.Text
client_name = TextBox2.Text
email_id = TextBox3.Text
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
Try
Dim str1 As String = "insert into BrandstikTesti(Comp_ID, client_name, email_id) values ('" + Comp_ID + "', '" + client_name + "', '" + email_id + "')"
con.Open()
Dim cmd As New SqlCommand(str1, con)
cmd.ExecuteNonQuery()
con.Close()
Catch ex As Exception
Response.Write("This Id already exist")
End Try
success.Text = "Client Added Succesfully"
End Sub
Private Sub BindListView()
Dim con As New SqlConnection("Data Source=SuRaj;Initial Catalog=Brandstik2; Integrated Security=True")
Using cmd As New SqlCommand()
cmd.CommandText = "SELECT Comp_ID, client_name, email_id FROM BrandstikTesti"
cmd.Connection = con
Using sda As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
sda.Fill(dt)
lvCustomers.DataSource = dt
lvCustomers.DataBind()
End Using
End Using
End Sub
End Class
如何在listview&按钮上点击emaild id?发送该特定邮件ID的邮件。
答案 0 :(得分:1)
当一个asp.net元素发回服务器时,它是使用asp的premade javascript函数__doPostBack
完成的:
<script>
function __doPostBack( eventTarget, eventArgument )
{
document.Form1.__EVENTTARGET.value = eventTarget;
document.Form1.__EVENTARGUMENT.value = eventArgument;
document.Form1.submit();
}
</script>
如果你想将html listview元素中的内容传递回你的代码,你可以拦截按钮点击并提交email_id
参数中的__EVENTARGUMENT
,并将其发送回服务器。
例如,您可以在使用onClientClick
回发之前在asp.net按钮上运行javascript函数:
<asp:Button ID="BT_Send" runat="server" Text="Send" OnClick="BT_Send_Click" OnClientClick="Submit_Stuff" />
function Submit_Stuff(){
//get your email id here
var _email_id = "blablabla1";
//manually cause a postback with the email id as argument
__doPostBack('<%=BT_Send.ClientID%>',_email_id );
return false;
}
并且在您的代码中,无论是在页面加载还是在BT_Send_Click
函数上,您都可以检索参数:
Dim email_id As String = Request.Form("__EVENTARGUMENT")