目前,一旦用户单击位于网格视图中的图像按钮,我的应用程序就可以打开带有默认收件人的Outlook电子邮件。此的 aspx 代码如下所示;
<asp:ImageButton ID="LinkEmail" OnClick="openClient" CommandArgument='<%# Eval("customerId") %>'
ToolTip="Send a Email to this customer" ImageUrl="~/SiteElements/Images/email_icon.jpg"
Width="16px" Height="16px" runat="server" />
我有一个 ID 为"custEmail"的绑定字段数据字段,如果客户电子邮件链接到他们的帐户,则在数据网格中显示客户电子邮件。用于打开Outlook应用程序的代码取自此问题,我添加的唯一补充是电子邮件发送到的地址;
Protected Sub openClient(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim Out1 As Object
Out1 = CreateObject("Outlook.Application")
If Out1 IsNot Nothing Then
Dim omsg As Object
omsg = Out1.CreateItem(0) '=Outlook.OlItemType.olMailItem'
omsg.To = "sample.email@test.com"
'set message properties here...'
omsg.Display(True)
End If
我想做的是将示例电子邮件替换为在数据网格中为客户显示的电子邮件。当我尝试这样做时;
omsg.To = custEmail
隐藏的代码找不到此绑定字段数据字段。
如何允许我的代码隐藏看到"custEmail"BoundField,以便我可以流行"omsg。使用客户电子邮件地址的收件人?
我建议您在 ImageButton 中将客户电子邮件地址作为CommandArgument
传递,并添加另一个属性CommandName
。
<asp:ImageButton ID="LinkEmail" OnClick="openClient"
CommandName="SendEmail"
CommandArgument='<%# Eval("CustomerEmail") %>'
ToolTip="Send a Email to this customer"
ImageUrl="~/SiteElements/Images/email_icon.jpg"
Width="16px" Height="16px" runat="server" />
接下来OnRowCommand
GridView 中添加事件:
<asp:GridView ID="GridView1" runat="server"
OnRowCommand="GridView1_RowCommand">
</asp:GridView>
在代码隐藏中:
Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs)
If e.CommandName = "SendEmail" Then
Dim CustomerEmailAddress = e.CommandArgument
Dim Out1 As Object
Out1 = CreateObject("Outlook.Application")
If Out1 IsNot Nothing Then
Dim omsg As Object
omsg = Out1.CreateItem(0) '=Outlook.OlItemType.olMailItem'
omsg.To = CustomerEmailAddress
'set message properties here...'
omsg.Display(True)
End If
End If
End Sub