我想从网格视图中获取ItemTemplate值以填充MailTo:字符串,然后在单击“发送电子邮件”按钮时根据网格视图中的复选框设置href。
如果对我而言,使用c#更加容易,我愿意使用它,但主要是我只想从Email TemplateField中提取电子邮件,并将其传递给href。
我只想打开客户的电子邮件,然后根据选中的复选框使用GridView1中的电子邮件地址填充其电子邮件(Outlook)的“邮件至:”部分,而不使用onClick作为复选框。
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" DataSourceID="SqlDataSource1" Height="158px" Width="449px" CssClass="auto-style2">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="checkboxSelectAll" onclick="HeaderCheckBoxClick(this);" runat="server" />
<br />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" onclick="ChildCheckBoxClick(this);" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Vendor_Name" HeaderText="Vendor" SortExpression="Vendor_Name" />
<asp:TemplateField HeaderText="Email" SortExpression="Email">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Email") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
</Columns>
<EmptyDataTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</EmptyDataTemplate>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
<div>
<input type="button" onclick="javascript: SendEmails();" value="Send" id="EmailButton" />
</div>
<script type="text/javascript">
var EmailAddresses = document.getElementById('<%=GridView1.ClientID %>');
function AddRemoveEmailAddress(checkbox, emailaddress) {
if (checkbox.checked == true) {
EmailAddresses.push(emailaddress);
}
else {
EmailAddresses.remove(emailaddress);
}
}
function SendEmails() {
var emailString = "";
for (i = 0; i < EmailAddresses.length; i++) {
emailString += EmailAddresses[i] + ";";
}
document.location.href = 'mailto:' + emailString;
}
</script>