i filled a gridview with tblUser, now gridview has a checkbox file (status), which is used to activate newly registered users,

so i want to inform user via mail when admins activates him, mean when i (admin) checks checkbox field true, in edit mode of girdview then at that moment the user should get notification that u have been activated ,

mail code , + other neccessary code is prepared but i can't figure out that how to send mail at that time when i click check box, :(

here is my code :

<%@ Page Language="C#" MasterPageFile="~/MasterPageAdministration.master" AutoEventWireup="true" CodeFile="adminViewEmployers.aspx.cs" Inherits="adminViewEmployers" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div class="superAdminContent">
  <h3>Employers</h3>
  <asp:TextBox ID="txtboxEmplyrName" runat="server"></asp:TextBox>
  <asp:Button ID="btnSrchEmplyrName" runat="server" Text="Search"
   style="height: 26px" onclick="btnSrchEmplyrName_Click" />
   Or
  <asp:Button ID="btnViewAllEmplyrs" runat="server" Text="View All"
            onclick="btnViewAllEmplyrs_Click" />
  <asp:Button ID="btnClrScreen" runat="server" Text="Clear" />
 </div>
 <div class="superAdminGridViewContent" >
     <asp:GridView ID="GridViewAdminViewEmplys" runat="server" AllowPaging="True"
         AutoGenerateColumns="False" DataKeyNames="userid"
         DataSourceID="SqlDataSource1" AllowSorting="True">
         <Columns>
             <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
             <asp:HyperLinkField DataNavigateUrlFields="userid"
                 DataNavigateUrlFormatString="~/adminViewEmplyrFurther.aspx?userid={0}"
                 DataTextField="userid" DataTextFormatString="{0}" HeaderText="Userid"
                 InsertVisible="False" NavigateUrl="~/adminViewEmplyrFurther.aspx"
                 SortExpression="userid" />
             <asp:BoundField DataField="fullname" HeaderText="fullname"
                 SortExpression="fullname" />
             <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
             <asp:BoundField DataField="question" HeaderText="question"
                 SortExpression="question" />
             <asp:BoundField DataField="answers" HeaderText="answers"
                 SortExpression="answers" />
             <asp:BoundField DataField="doc" HeaderText="doc" SortExpression="doc" />
             <asp:BoundField DataField="roleid" HeaderText="roleid"
                 SortExpression="roleid" />
             <asp:CheckBoxField DataField="active" HeaderText="Status" SortExpression="active" ReadOnly="false" />

         </Columns>
     </asp:GridView>

     <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
         AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
         DataKeyNames="userid" DataSourceID="SqlDataSource2" ForeColor="#333333"
         Visible="false"
         GridLines="None">
         <RowStyle BackColor="#E3EAEB" />
         <Columns>
             <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
             <asp:HyperLinkField DataNavigateUrlFields="userid"
                 DataNavigateUrlFormatString="~/adminViewEmplyrFurther.aspx?userid={0}"
                 DataTextField="userid" DataTextFormatString="{0}" HeaderText="Userid"
                 InsertVisible="False" NavigateUrl="~/adminViewEmplyrFurther.aspx"
                 SortExpression="userid" />
             <asp:BoundField DataField="fullname" HeaderText="fullname"
                 SortExpression="fullname" />
             <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
             <asp:BoundField DataField="question" HeaderText="question"
                 SortExpression="question" />
             <asp:BoundField DataField="answers" HeaderText="answers"
                 SortExpression="answers" />
             <asp:BoundField DataField="doc" HeaderText="doc" SortExpression="doc" />
             <asp:BoundField DataField="roleid" HeaderText="roleid"
                 SortExpression="roleid" />
         </Columns>
         <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
         <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
         <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
         <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
         <EditRowStyle BackColor="#7C6F57" />
         <AlternatingRowStyle BackColor="White" />

     </asp:GridView>
     <asp:SqlDataSource ID="SqlDataSource2" runat="server"
         ConnectionString="<%$ ConnectionStrings:Waleed_orsfinalConnectionString7 %>"
         DeleteCommand="DELETE FROM [tblUser] WHERE [userid] = @userid"
         InsertCommand="INSERT INTO [tblUser] ([fullname], [email], [question], [answers], [doc], [roleid]) VALUES (@fullname, @email, @question, @answers, @doc, @roleid)"
         SelectCommand="SELECT [userid], [fullname], [email], [question], [answers], [doc], [roleid] FROM [tblUser] where roleid=2"
         UpdateCommand="UPDATE [tblUser] SET [fullname] = @fullname, [email] = @email, [question] = @question, [answers] = @answers, [doc] = @doc, [roleid] = @roleid WHERE [userid] = @userid">
         <DeleteParameters>
             <asp:Parameter Name="userid" Type="Int32" />
         </DeleteParameters>
         <UpdateParameters>
             <asp:Parameter Name="fullname" Type="String" />
             <asp:Parameter Name="email" Type="String" />

             <asp:Parameter Name="question" Type="String" />
             <asp:Parameter Name="answers" Type="String" />
             <asp:Parameter DbType="Date" Name="doc" />
             <asp:Parameter Name="roleid" Type="Int32" />
             <asp:Parameter Name="userid" Type="Int32" />
         </UpdateParameters>
         <InsertParameters>
             <asp:Parameter Name="fullname" Type="String" />
             <asp:Parameter Name="email" Type="String" />

             <asp:Parameter Name="question" Type="String" />
             <asp:Parameter Name="answers" Type="String" />
             <asp:Parameter DbType="Date" Name="doc" />
             <asp:Parameter Name="roleid" Type="Int32" />
         </InsertParameters>
     </asp:SqlDataSource>
     <asp:SqlDataSource ID="SqlDataSource1" runat="server"
         ConnectionString="<%$ ConnectionStrings:Waleed_orsfinalConnectionString5 %>"
         DeleteCommand="DELETE FROM [tblUser] WHERE [userid] = @userid"
         InsertCommand="INSERT INTO [tblUser] ([fullname], [email], [question], [answers], [doc], [roleid]) VALUES (@fullname, @email, @question, @answers, @doc, @roleid)"
         SelectCommand="SELECT [userid], [fullname], [email], [question], [answers], [doc], [roleid],[active] FROM [tblUser] where fullname=@emplyrName AND roleid=2"
         UpdateCommand="UPDATE [tblUser] SET [fullname] = @fullname, [email] = @email, [question] = @question, [answers] = @answers, [doc] = @doc, [roleid] = @roleid, [active]= @active WHERE [userid] = @userid">
         <DeleteParameters>
             <asp:Parameter Name="userid" Type="Int32" />
         </DeleteParameters>
         <UpdateParameters>
             <asp:Parameter Name="fullname" Type="String" />
             <asp:Parameter Name="email" Type="String" />
             <asp:Parameter Name="question" Type="String" />
             <asp:Parameter Name="answers" Type="String" />
             <asp:Parameter DbType="Date" Name="doc" />
             <asp:Parameter Name="roleid" Type="Int32" />
             <asp:Parameter Name="active" Type="Boolean" />
             <asp:Parameter Name="userid" Type="Int32" />
         </UpdateParameters>
         <InsertParameters>
             <asp:Parameter Name="fullname" Type="String" />
             <asp:Parameter Name="email" Type="String" />
             <asp:Parameter Name="question" Type="String" />
             <asp:Parameter Name="answers" Type="String" />
             <asp:Parameter DbType="Date" Name="doc" />
             <asp:Parameter Name="roleid" Type="Int32" />
             <asp:Parameter Name="active" Type="Boolean" />
         </InsertParameters>
         <SelectParameters>
             <asp:ControlParameter ControlID="txtboxEmplyrName" Name="emplyrName" Type="String" PropertyName="text" />
        </SelectParameters>
     </asp:SqlDataSource>
 </div>
</asp:Content>

what comes to mind for me is that you can use these events...

GridView.RowUpdating Event

and/or

GridView.RowEditing Event

When you add these events and others (you could do for deletes as well..), you can trigger specific subroutines to run when these events occur. So for example, when you enable the check box during an edit or update event, you can include your code to email the user.

ok and how to get particular checkbox field and also userid field for every row via code
help plz

@jorgem: ok i did what u suggested but now i am getting error:

***Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.***

.cs code:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class adminViewEmployers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

       // GridViewAdminViewEmplys.Visible = false;

    }
    //protected void btnSearchEmplyr_Click(object sender, EventArgs e)
    //{
    //    GridViewAdminViewEmplys.Visible = true;
    //    String conString = "Data Source=COSANOSTRA;Initial Catalog=Waleed_orsfinal;Integrated Security=True";
    //    //Sql Connection
    //    SqlConnection con = new SqlConnection(conString);
    //    //Sql Command
    //    String query = "Select * from tblUser where roleid=2";
    //    SqlCommand com = new SqlCommand(query, con);
    //    //Sql DataAdapter
    //    SqlDataAdapter da = new SqlDataAdapter(com);
    //    //Sql DataSet
    //    DataSet ds = new DataSet();
    //    try
    //    {
    //        con.Open();
    //        da.Fill(ds, "tblUser");
    //    }
    //    catch (Exception ex)
    //    {
    //        Response.Write("Error:" + ex.Message);
    //    }
    //    finally
    //    {
    //        con.Close();
    //    }
    //    //GridView
    //    GridViewAdminViewEmplys.DataSource = ds;
    //    GridViewAdminViewEmplys.DataBind();
    //}

    protected void GridViewAdminViewEmplys_RowUpdating(Object sender, GridViewUpdatedEventArgs e)
    {
        GridViewRow gvr = GridViewAdminViewEmplys.SelectedRow;
        CheckBox chk = (CheckBox)gvr.Cells[8].Controls[0];
        Response.Write(chk.Checked);
    }

    protected void btnSrchEmplyrName_Click(object sender, EventArgs e)
    {
        GridViewAdminViewEmplys.Visible = true;
        GridView1.Visible = false;
    }
    protected void btnViewAllEmplyrs_Click(object sender, EventArgs e)
    {
        GridView1.Visible = true;
        GridViewAdminViewEmplys.Visible = false;

    }
}

.aspx code:

<%@ Page Language="C#" MasterPageFile="~/MasterPageAdministration.master" AutoEventWireup="true" CodeFile="adminViewEmployers.aspx.cs" Inherits="adminViewEmployers" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div class="superAdminContent">
  <h3>Employers</h3>
  <asp:TextBox ID="txtboxEmplyrName" runat="server"></asp:TextBox>
  <asp:Button ID="btnSrchEmplyrName" runat="server" Text="Search" 
   style="height: 26px" onclick="btnSrchEmplyrName_Click" />
   Or
  <asp:Button ID="btnViewAllEmplyrs" runat="server" Text="View All" 
            onclick="btnViewAllEmplyrs_Click" />      
  <asp:Button ID="btnClrScreen" runat="server" Text="Clear" />
 </div>
 <div class="superAdminGridViewContent" >
     <asp:GridView ID="GridViewAdminViewEmplys" runat="server" AllowPaging="True"
         AutoGenerateColumns="False" DataKeyNames="userid"
         DataSourceID="SqlDataSource1" AllowSorting="True" 
         OnRowUpdated="GridViewAdminViewEmplys_RowUpdating">
         <Columns>
             <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
             <asp:HyperLinkField DataNavigateUrlFields="userid" 
                 DataNavigateUrlFormatString="~/adminViewEmplyrFurther.aspx?userid={0}" 
                 DataTextField="userid" DataTextFormatString="{0}" HeaderText="Userid" 
                 InsertVisible="False" NavigateUrl="~/adminViewEmplyrFurther.aspx" 
                 SortExpression="userid" />
             <asp:BoundField DataField="fullname" HeaderText="fullname" 
                 SortExpression="fullname" />
             <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
             <asp:BoundField DataField="question" HeaderText="question" 
                 SortExpression="question" />
             <asp:BoundField DataField="answers" HeaderText="answers" 
                 SortExpression="answers" />
             <asp:BoundField DataField="doc" HeaderText="doc" SortExpression="doc" />
             <asp:BoundField DataField="roleid" HeaderText="roleid" 
                 SortExpression="roleid" />
             <asp:CheckBoxField DataField="active" HeaderText="Status" 
                 SortExpression="active" ReadOnly="false" />

         </Columns>
     </asp:GridView>

     <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
         AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
         DataKeyNames="userid" DataSourceID="SqlDataSource2" ForeColor="#333333" 
         Visible="false"
         GridLines="None">
         <RowStyle BackColor="#E3EAEB" />
         <Columns>
             <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
             <asp:HyperLinkField DataNavigateUrlFields="userid" 
                 DataNavigateUrlFormatString="~/adminViewEmplyrFurther.aspx?userid={0}" 
                 DataTextField="userid" DataTextFormatString="{0}" HeaderText="Userid" 
                 InsertVisible="False" NavigateUrl="~/adminViewEmplyrFurther.aspx" 
                 SortExpression="userid" />
             <asp:BoundField DataField="fullname" HeaderText="fullname" 
                 SortExpression="fullname" />
             <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
             <asp:BoundField DataField="question" HeaderText="question" 
                 SortExpression="question" />
             <asp:BoundField DataField="answers" HeaderText="answers" 
                 SortExpression="answers" />
             <asp:BoundField DataField="doc" HeaderText="doc" SortExpression="doc" />
             <asp:BoundField DataField="roleid" HeaderText="roleid" 
                 SortExpression="roleid" />
         </Columns>
         <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
         <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
         <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
         <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
         <EditRowStyle BackColor="#7C6F57" />
         <AlternatingRowStyle BackColor="White" />

     </asp:GridView>
     <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
         ConnectionString="<%$ ConnectionStrings:Waleed_orsfinalConnectionString7 %>" 
         DeleteCommand="DELETE FROM [tblUser] WHERE [userid] = @userid" 
         InsertCommand="INSERT INTO [tblUser] ([fullname], [email], [question], [answers], [doc], [roleid]) VALUES (@fullname, @email, @question, @answers, @doc, @roleid)" 
         SelectCommand="SELECT [userid], [fullname], [email], [question], [answers], [doc], [roleid] FROM [tblUser] where roleid=2" 
         UpdateCommand="UPDATE [tblUser] SET [fullname] = @fullname, [email] = @email, [question] = @question, [answers] = @answers, [doc] = @doc, [roleid] = @roleid WHERE [userid] = @userid">
         <DeleteParameters>
             <asp:Parameter Name="userid" Type="Int32" />
         </DeleteParameters>
         <UpdateParameters>
             <asp:Parameter Name="fullname" Type="String" />
             <asp:Parameter Name="email" Type="String" />

             <asp:Parameter Name="question" Type="String" />
             <asp:Parameter Name="answers" Type="String" />
             <asp:Parameter DbType="Date" Name="doc" />
             <asp:Parameter Name="roleid" Type="Int32" />
             <asp:Parameter Name="userid" Type="Int32" />
         </UpdateParameters>
         <InsertParameters>
             <asp:Parameter Name="fullname" Type="String" />
             <asp:Parameter Name="email" Type="String" />

             <asp:Parameter Name="question" Type="String" />
             <asp:Parameter Name="answers" Type="String" />
             <asp:Parameter DbType="Date" Name="doc" />
             <asp:Parameter Name="roleid" Type="Int32" />
         </InsertParameters>
     </asp:SqlDataSource>
     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
         ConnectionString="<%$ ConnectionStrings:Waleed_orsfinalConnectionString5 %>" 
         DeleteCommand="DELETE FROM [tblUser] WHERE [userid] = @userid" 
         InsertCommand="INSERT INTO [tblUser] ([fullname], [email], [question], [answers], [doc], [roleid]) VALUES (@fullname, @email, @question, @answers, @doc, @roleid)" 
         SelectCommand="SELECT [userid], [fullname], [email], [question], [answers], [doc], [roleid],[active] FROM [tblUser] where fullname=@emplyrName AND roleid=2" 
         UpdateCommand="UPDATE [tblUser] SET [fullname] = @fullname, [email] = @email, [question] = @question, [answers] = @answers, [doc] = @doc, [roleid] = @roleid, [active]= @active WHERE [userid] = @userid">
         <DeleteParameters>
             <asp:Parameter Name="userid" Type="Int32" />
         </DeleteParameters>
         <UpdateParameters>
             <asp:Parameter Name="fullname" Type="String" />
             <asp:Parameter Name="email" Type="String" />
             <asp:Parameter Name="question" Type="String" />
             <asp:Parameter Name="answers" Type="String" />
             <asp:Parameter DbType="Date" Name="doc" />
             <asp:Parameter Name="roleid" Type="Int32" />
             <asp:Parameter Name="active" Type="Boolean" />
             <asp:Parameter Name="userid" Type="Int32" />
         </UpdateParameters>
         <InsertParameters>
             <asp:Parameter Name="fullname" Type="String" />
             <asp:Parameter Name="email" Type="String" />
             <asp:Parameter Name="question" Type="String" />
             <asp:Parameter Name="answers" Type="String" />
             <asp:Parameter DbType="Date" Name="doc" />
             <asp:Parameter Name="roleid" Type="Int32" />
             <asp:Parameter Name="active" Type="Boolean" />
         </InsertParameters>
         <SelectParameters>
             <asp:ControlParameter ControlID="txtboxEmplyrName" Name="emplyrName" Type="String" PropertyName="text" />
        </SelectParameters>
     </asp:SqlDataSource>
 </div>
</asp:Content>

actually problem was using .SelectedRow, for which i hadn't any select button, so i used GV.Rows[index].cells[8].control[0] and it worked

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.