Category: Asp.net

Mar 02 2010

How to send email in asp.net

Web.config

<appSettings>

<add key=”SMTP” value=”smtp.gmail.com”/>

<add key=”FROMEMAIL” value=”Gmail UserName”/>

<add key=”FROMPWD” value=”GiveGmailPassword”/>

</appSettings>

give correct gmail username like  lokeshasp@gmail.com

give correct gmail password

Giving correct username and password of gmail. Gmail  SMTP server will assume is an authenticated user. For this authenticated details of gmail mails will sent to yahoo,gmail,etc..

using System.Net.Mail;

write below code in page load or button click

MailMessage mail = new MailMessage();

mail.To.Add(”lokeshdotnet09@yahoo.com”);

mail.From = new MailAddress(”lokeshasp@gmail.com”);

mail.Subject = “Test Email”;

string Body = “<b>Welcome to lotus.Com!!</b>”;

mail.Body = Body;

mail.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient();

smtp.Host = ConfigurationManager.AppSettings["SMTP"];

smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["FROMEMAIL"], ConfigurationManager.AppSettings["FROMPWD"]);

smtp.EnableSsl = true;

smtp.Send(mail);

Mar 02 2010

Making GridView Rows or Individual Cells Clickable and Selectable.

Getting gridview row cells values by clicking use GridView1_RowDataBound , add DataKeyNames,onselectedindexchanging

<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False”

BackColor=”White” BorderColor=”#999999″

BorderStyle=”None” BorderWidth=”1px”

CellPadding=”3″ Font-Names=”Verdana”

Font-Size=”9pt” GridLines=”Vertical”                                          onrowdatabound=”GridView1_RowDataBound”

DataKeyNames=”EmpID onselectedindexchanging=”GridView1_SelectedIndexChanging” >

<RowStyle BackColor=”#EEEEEE” ForeColor=”Black” />

<Columns>

<asp:ButtonField CommandName=”Select” Visible=”False” />

<asp:TemplateField>

<HeaderTemplate>

Details                                                                                                                </HeaderTemplate>

<ItemTemplate>

<asp:LinkButton ID=”lbtnEditUserData” runat=”server”

<asp:LinkButton ID=”lbtnRegisterDetails” runat=”server”

CommandArgument=’<%# DataBinder.Eval(Container.DataItem,”EmpID”) %>’

Font-Underline=”False” oncommand=”lbtnRegisterDetails_Command”>Details</asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

<asp:BoundField DataField=”Ecode” HeaderText=”ECode” />

<asp:BoundField DataField=”EName” HeaderText=”Employee_Name” />

<asp:BoundField DataField=”EmailID” HeaderText=”EmailID” />

<asp:BoundField DataField=”ProdUserName” HeaderText=”UserName” />

<asp:BoundField DataField=”MobileNo” HeaderText=”MobileNo” />

</Columns>

<SelectedRowStyle BackColor=”#008A8C” Font-Bold=”True” ForeColor=”White” />

<HeaderStyle CssClass=”strip” Font-Bold=”True” ForeColor=”Black” />

</asp:GridView>

<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>

<asp:TextBox ID=”TextBox2″ runat=”server”></asp:TextBox>

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.GridView1, “Select$” + e.Row.RowIndex);

}

}

protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)

{

//Retrieve empcode and empname by clicking gridview row

GridViewRow row = GridView1.Rows[e.NewSelectedIndex];

TextBox1.Text = row.Cells[2].Text;  // getting EmpCode contain in gridview cells[2]

TextBox2.Text = row.Cells[3].Text;  //getting EmpName contain in gridview cells[3]

}

Alibi3col theme by Themocracy