0

net application. I have one gridview with checkboxes.Whenever checkbox is checked i want to send email to users. My columns of gridview are id,name,emailid etc. Whenever checkbox is checked i want to send email. I written javascript code to catch up all the emailids from gridview and pushing all the email ids to the array. I am confusing how to take these id's to the server side. This is my button.

<asp:Button ID="Button1" class="submitLink blueButton" runat="server" Text="GETID" OnClientClick="javascript:sendEmail()" OnClick="Button1_Click" />

Using below line of code I am able to get the required email id's

$('#<%= gdvRegretletter.ClientID %> input[type="CheckBox"]').each(function () {
    if ($(this).closest('tr').find('input[type="checkbox"]').prop("checked") == true)
        email.push($(this).closest('tr').find('td:eq(3)').text().trim());
});

Array email will be capturing all the required email id's but i want these values inside the Button1_Click event in server side. May i have some idea to achieve this? Thank you for your time.

VDWWD
  • 35,079
  • 22
  • 62
  • 79
Niranjan Godbole
  • 2,135
  • 7
  • 43
  • 90

1 Answers1

0

You could loop all the rows in the GridView and see which CheckBox has been checked. In this snippet the email address is also displayed in the GridView in a Literal, but there are a lot of other ways do get the email address, either from the GridView or it's original source.

<asp:GridView ID="GridView1" runat="server" DataKeyNames="Id">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="CheckBox1" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Literal ID="Literal1" runat="server" Text='<%# Eval("email") %>'></asp:Literal>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>


protected void Button1_Click(object sender, EventArgs e)
{
    //loop all the rows in the gridview
    foreach (GridViewRow row in GridView1.Rows)
    {
        //find the checkbox with findcontrol and cast it back to one
        CheckBox checkbox = row.FindControl("CheckBox1") as CheckBox;

        //is it checked?
        if (checkbox.Checked == true)
        {
            //do the same for the label with the email address
            Literal literal = row.FindControl("Literal1") as Literal;

            string email = literal.Text;

            //send email
        }
    }
}
VDWWD
  • 35,079
  • 22
  • 62
  • 79