I cant able to read selected values in gridview... it returns null value while debugging..
kindly fix this issue..
im trying to send email to selected users frm gridview using checkbox
im getting error in
string email =row.Cells[2].Text;
s.To.Add(email);
It cant the read the selected values in gridview...
source file-------------------
<%@ Page Language="C#" Debug="true" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
subject
</td>
<td>
<asp:TextBox ID="txtsubject" runat="server"></asp:TextBox>
</td> </tr>
<tr>
<td>message</td>
<td>
<asp:TextBox ID="txtmessage" runat="server" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
</table>
</div>
<div>
</div>
<div>
</div>
<div>
<asp:Button ID="btnsubmit" runat="server" Text="Send" onclick="btnsubmit_Click" />
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="sno">
<ItemTemplate>
<asp:Label ID="lbl1" runat="server" Text='<%#bind("sno") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="name">
<ItemTemplate>
<asp:Label ID="lbl2" runat="server" Text='<%#bind("name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="mail">
<ItemTemplate>
<asp:Label ID="lbl3" runat="server" Text='<%#bind("mailid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkhdr" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>
aspx.cs file.........................................
protected void btnsubmit_Click(object sender, EventArgs e)
{
string id = string.Empty;
MailMessage s = new MailMessage();
s.Subject = txtsubject.Text;
s.Body = txtmessage.Text;
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chk = (CheckBox)row.FindControl("CheckBox1");
{
if (chk.Checked==true)
{
string email =row.Cells[2].Text;
s.To.Add(email);
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential p = new NetworkCredential();
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("
[email protected]", "********");
smtp.EnableSsl = true;
smtp.Send(s);
}
}
}
}