tags:

views:

141

answers:

3

Hi,

I have a grid view control in my application.

Please see the below code.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CPUserID" DataSourceID="GetSelectDelegatesDataSource">
<Columns>
<asp:BoundField HeaderStyle-CssClass="gridview_header" HeaderStyle-ForeColor="White" Visible="false" DataField="EmailAddress" HeaderText="Email Address" SortExpression="EmailAddress">

<HeaderStyle CssClass="gridview_header" ForeColor="White"></HeaderStyle>
</asp:BoundField>

<asp:TemplateField HeaderText="Select">

<HeaderTemplate>                                    
<input id="masterCheck" type="checkbox" />                                
</HeaderTemplate>                                
<ItemTemplate>                                    
<asp:CheckBox runat="server" ID="chkSelect" />                                
</ItemTemplate>                                
<HeaderStyle CssClass="gridview_header" ForeColor="White"></HeaderStyle>

</asp:TemplateField>
</Columns>
</asp:GridView>

And I have a image button

<asp:ImageButton ID="ibtnSendInvites" Visible="false" runat="server" ImageUrl="~/images1/send_button.png" />

If you see above code you can find that there is check box functionality in my gridview. I have email address boundfield in my gridview. I want to send an email to the email addresses which are been checked in gridview.

Please provide the vb.net code for the same

A: 

Hi,

System.Web.Mail provide the functionality to send mail from .Net framework. Download the sample project Send Mail- codeproject and see how this is implemented.

Cheers

Ramesh Vel

Ramesh Vel
what about reading all the emailaddresses in gridview which are checked and then sending email to them?
MKS
System.Net.Mail from .NET 2.0 and newer, not Sytem.Web.Mail
Jeff Tucker
A: 

Check this link on BulkEditGridView. It's just like a GridView, but you can edit (or perform actions on) multiple rows of a gridview with one click. I use it and love it.

Jason
+1  A: 

Very quickly thrown together, you can get the jist.. I didn't test it or anything.

 Dim emailList As New List(Of String)
 For Each curRow As GridViewRow In GridView1.Rows
      Dim chkSelect As CheckBox = CType(curRow.Cells(1).FindControl("chkSelect"), CheckBox)

      If chkSelect.Checked Then
           emailList.Add(curRow.Cells(0).Text)
      End If
 Next

 ' you now have a generic list of email addresses..
Nicholas H
Thanks Nicholas for the code, I have a sendemail function to send the emails. How can I use generic list to send the email addresses using my sendemail function. Please write the code. Which will read our generic list and further send the emails to the emailaddress inside the list. Thanks
MKS
Well you can either loop through and send individual emails or send to the entire "to" at once. It's up to you. I think you'd need to open another question.
Nicholas H
Hi Nicholas, I want both the functionality for sending the emails i.e for checked and as well as for whole of the email address, please write the code here in question or let me know should i open new question for the same. Please suggest
MKS
I already gave you the code that produces a list of checked email addresses. Simply loop through the list and call your SendEmail method.
Nicholas H
Please accept my answer if it has helped you.
Nicholas H