Friday, August 28, 2026

Gridview send email

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.IO;

using System.Text;

using System.Net.Mail;


namespace connectivity

{

    public partial class grid_email : System.Web.UI.Page

    {

        SqlConnection con;

        SqlCommand com;

        SqlDataReader dr;


        protected void Page_Load(object sender, EventArgs e)

        {

            if (!IsPostBack)

            {

                display();

            }

        }

        protected void display()

        {

            //select query Implementation//

            string path = @"Data Source=DESKTOP-9KU60QI;Initial Catalog=college;Integrated Security=True";

            con = new SqlConnection(path);

            con.Open();


            string a = "select * from dbconnect";

            com = new SqlCommand(a, con);


            dr = com.ExecuteReader();


            GridView1.DataSource = dr;

            GridView1.DataBind();


            dr.Close();


        }

        public override void VerifyRenderingInServerForm(Control control)

        {

            // Required for GridView rendering

        }


        protected void Button1_Click(object sender, EventArgs e)

        {

            try

            {

                // Convert GridView to HTML

                StringBuilder sb = new StringBuilder();


                using (StringWriter sw = new StringWriter(sb))

                {

                    using (HtmlTextWriter hw = new HtmlTextWriter(sw))

                    {

                        GridView1.RenderControl(hw);

                    }

                }

                //email programming//

                string gridhtml = sb.ToString();


                //create mail object//

                MailMessage msg = new MailMessage();

                //set property//

                msg.To.Add(TextBox1.Text);

                msg.From = new MailAddress("vrushalihatewar@gmail.com");

                msg.Subject = "This is testing mail";


                msg.Body = @"

                <html>

                <body>

                    <h2>GridView Report</h2>

                    <p>Please find the report below:</p>

                    " + gridhtml + @"

                </body>

                </html>";




                //set mail format//

                msg.IsBodyHtml = true;



                //create smtp client object//

                SmtpClient stp = new SmtpClient();

                //set the smtp property//

                stp.Host = "smtp.gmail.com";

                stp.Credentials = new System.Net.NetworkCredential("vrushalihatewar@gmail.com", "uzvq dloh ljjk nonh");

                stp.EnableSsl = true;


                //send mail//

                stp.Send(msg);

                Response.Write("mail sent sucessfully");


            }


            catch(Exception ex)

            {

                Response.Write(ex);

            }

        }

    }

}

Gridview to email

 using System;

using System.IO;

using System.Net;

using System.Net.Mail;

using System.Text;

using System.Web.UI;

using System.Web.UI.WebControls;


protected void btnSendEmail_Click(object sender, EventArgs e)

{

    try

    {

        // Convert GridView to HTML

        StringBuilder sb = new StringBuilder();


        using (StringWriter sw = new StringWriter(sb))

        {

            using (HtmlTextWriter hw = new HtmlTextWriter(sw))

            {

                GridView1.RenderControl(hw);

            }

        }


        string gridHtml = sb.ToString();


        // Create email

        MailMessage mail = new MailMessage();


        mail.From = new MailAddress("yourmail@gmail.com");

        mail.To.Add("receiver@gmail.com");


        mail.Subject = "GridView Report";

        mail.Body = @"

            <html>

            <body>

                <h2>GridView Report</h2>

                <p>Please find the report below:</p>

                " + gridHtml + @"

            </body>

            </html>";


        mail.IsBodyHtml = true;


        // SMTP settings

        SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);


        smtp.EnableSsl = true;

        smtp.Credentials = new NetworkCredential(

            "yourmail@gmail.com",

            "YOUR_APP_PASSWORD"

        );


        smtp.Send(mail);


        Response.Write("<script>alert('Email sent successfully');</script>");

    }

    catch (Exception ex)

    {

        Response.Write("<script>alert('" +

            ex.Message.Replace("'", "") +

            "');</script>");

    }

}





Main code 

public override void VerifyRenderingInServerForm(Control control)

{

    // Required for GridView rendering

}


Hyper link control with EVAL PATH

<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("name") %>'  


NavigateUrl='<%# "~/news/" + Eval("filen") %>' ForeColor="Wheat"> </asp:HyperLink>


FILE UPLOAD MAX SIZE WITH SERVER FOLDER

 WEB CONFIG   FILE 

<?xml version="1.0"?>

<configuration>

  <system.web>



    <httpRuntime maxRequestLength="1048576" executionTimeout="999999"/>


    <customErrors mode="Off"></customErrors>

    <compilation debug="true" targetFramework="4.0"/>

  </system.web>

</configuration>


Folder Code 

 protected void Button1_Click(object sender, EventArgs e)

    {

        //file upload 


        FileUpload1.SaveAs(Server.MapPath(@"~/nsadmin/") + "//news//" + FileUpload1.FileName);

        Label1.Text = "File upload successfully please click save button to save record";

    }







Friday, July 24, 2026

GRIDVIEW PAGINING

 <asp:GridView ID="GridView1" runat="server" 

         
AutoGenerateColumns="False" 

AllowPaging="True" 

OnPageIndexChanging="GridView1_PageIndexChanging">


Code in C#

protected void BindProducts()
    {

        string cs =@"path";
        cn = new SqlConnection(cs);
        cn.Open();
        
        DataSet ds = new DataSet();
        string k = "select * from student";     
       SqlDataAdapter adp = new SqlDataAdapter (k,cn);
        adp.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }


protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

        GridView1.PageIndex = e.NewPageIndex;

        BindProducts();

    }

Sunday, June 28, 2026

Data Transfer Java Script using Local Storage

 

Page 1: index.html

<!DOCTYPE html>
<html>
<head>
<title>Page 1</title>
</head>
<body>

<h2>Student Information</h2>

<label>Enter Name:</label>
<input type="text" id="txtName">
<br><br>

<button onclick="sendData()">Next Page</button>

<script>
function sendData() {
var name = document.getElementById("txtName").value;

// Save data in Local Storage
localStorage.setItem("StudentName", name);

// Open second page
window.location.href = "result.html";
}
</script>

</body>
</html>

Page 2: result.html

<!DOCTYPE html>
<html>
<head>
<title>Page 2</title>
</head>
<body>

<h2>Student Details</h2>

<p>
Name :
<span id="displayName"></span>
</p>

<script>
// Get data from Local Storage
var name = localStorage.getItem("StudentName");

// Display data
document.getElementById("displayName").innerHTML = name;
</script>

</body>
</html>

Output

Page 1

Student Information

Enter Name: [Nilesh Gupta]

[Next Page]

⬇️ Click Next Page

Page 2

Student Details

Name : Nilesh Gupta

How It Works

  1. User enters a name on index.html.
  2. JavaScript stores the value using:

    localStorage.setItem("StudentName", name);
  3. The browser opens result.html.
  4. The second page retrieves the value:

    localStorage.getItem("StudentName");
  5. The name is displayed on the page.

This is one of the simplest ways to transfer data between HTML pages using only JavaScript, without any server-side code or database.

What is localStorage in JavaScript? Data Transfer B/W one page to another page

What is localStorage in JavaScript?

localStorage is a built-in JavaScript object that allows you to store data in the user's web browser as key-value pairs. The stored data remains available even after the browser is closed and reopened, until it is manually deleted or cleared.

Features of localStorage

  • Stores data in the browser.
  • Data is saved as string values.
  • Data remains available even after refreshing or closing the browser.
  • Data is stored only for the same website (same origin).
  • No server or database is required.

Syntax

Store Data

localStorage.setItem("key", "value");

Retrieve Data

var value = localStorage.getItem("key");

Remove One Item

localStorage.removeItem("key");

Remove All Items

localStorage.clear();

Example 1: Store Data

<!DOCTYPE html>
<html>
<head>
<title>LocalStorage Example</title>
</head>
<body>

<input type="text" id="txtName" placeholder="Enter Name">
<button onclick="saveData()">Save</button>

<script>
function saveData() {
var name = document.getElementById("txtName").value;

localStorage.setItem("StudentName", name);

alert("Data Saved Successfully");
}
</script>

</body>
</html>

Example 2: Display Stored Data

<!DOCTYPE html>
<html>
<head>
<title>Display Data</title>
</head>
<body>

<h2>Stored Name</h2>

<p id="result"></p>

<script>
var name = localStorage.getItem("StudentName");

document.getElementById("result").innerHTML = name;
</script>

</body>
</html>

Example 3: Remove Data

localStorage.removeItem("StudentName");

Example 4: Clear All Data

localStorage.clear();

Output

Before Saving

Enter Name : Nilesh Gupta

[Save]

After Displaying

Stored Name

Nilesh Gupta

Common localStorage Methods

MethodDescription
setItem(key, value)Stores data
getItem(key)Retrieves stored data
removeItem(key)Removes a specific item
clear()Removes all stored data
key(index)Returns the key at the given index
lengthReturns the number of stored items

Advantages

  • Easy to use.
  • No database or server required.
  • Data persists after the browser is closed.
  • Useful for user preferences, themes, shopping carts, and small amounts of application data.

Limitations

  • Stores only strings (objects must be converted using JSON.stringify() and JSON.parse()).
  • Typical storage limit is around 5–10 MB, depending on the browser.
  • Data is not secure—users can view and modify it through the browser's developer tools.
  • It should not be used to store sensitive information such as passwords or payment details.

localStorage is commonly used in front-end web applications to save small amounts of data locally without requiring a server or database.

Java script radio button event programming

 

JavaScript Radio Button Example with Result

This example allows the user to select a gender using radio buttons and displays the selected value when the button is clicked.

HTML + JavaScript Code

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Radio Button Example</title>

<script>
function showResult() {

var gender = "";

if (document.getElementById("male").checked) {
gender = "Male";
}
else if (document.getElementById("female").checked) {
gender = "Female";
}
else if (document.getElementById("other").checked) {
gender = "Other";
}
else {
gender = "Please select a gender.";
}

document.getElementById("result").innerHTML = gender;
}
</script>

</head>

<body>

<h2>JavaScript Radio Button Example</h2>

<input type="radio" id="male" name="gender"> Male <br><br>

<input type="radio" id="female" name="gender"> Female <br><br>

<input type="radio" id="other" name="gender"> Other <br><br>

<button onclick="showResult()">Show Result</button>

<h3>Selected Gender:</h3>
<p id="result"></p>

</body>
</html>

Output

Before Clicking Button

( ) Male
( ) Female
( ) Other

[ Show Result ]

Example 1

If the user selects Male:

Selected Gender:
Male

Example 2

If the user selects Female:

Selected Gender:
Female

Example 3

If no option is selected:

Selected Gender:
Please select a gender.

Learning Points

  • input type="radio" creates a radio button.
  • Radio buttons with the same name belong to the same group.
  • .checked returns true if a radio button is selected.
  • document.getElementById() accesses an HTML element by its ID.
  • .innerHTML displays the selected value in the page.

This is a simple and beginner-friendly JavaScript radio button example suitable for students learning HTML and JavaScript.

Java Script Check box programming

 Here's a simple JavaScript Checkbox Example with output.

Example 1: Check if Checkbox is Selected

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Checkbox Example</title>
</head>
<body>

<h2>Checkbox Example</h2>

<input type="checkbox" id="chkAgree"> I Agree to the Terms & Conditions
<br><br>

<button onclick="checkStatus()">Submit</button>

<p id="result"></p>

<script>
function checkStatus() {
var checkbox = document.getElementById("chkAgree");

if (checkbox.checked) {
document.getElementById("result").innerHTML =
"✅ Checkbox is Checked.";
}
else {
document.getElementById("result").innerHTML =
"❌ Checkbox is Not Checked.";
}
}
</script>

</body>
</html>

Result

Case 1: Checkbox Checked

✅ Checkbox is Checked.

Case 2: Checkbox Not Checked

❌ Checkbox is Not Checked.

Example 2: Multiple Checkboxes

<!DOCTYPE html>
<html>
<head>
<title>Multiple Checkbox Example</title>
</head>
<body>

<h2>Select Your Skills</h2>

<input type="checkbox" id="html"> HTML <br>
<input type="checkbox" id="css"> CSS <br>
<input type="checkbox" id="js"> JavaScript <br><br>

<button onclick="showSkills()">Show Selected Skills</button>

<p id="output"></p>

<script>
function showSkills() {

var result = "";

if(document.getElementById("html").checked)
result += "HTML ";

if(document.getElementById("css").checked)
result += "CSS ";

if(document.getElementById("js").checked)
result += "JavaScript ";

if(result == "")
result = "No Skill Selected";

document.getElementById("output").innerHTML = result;
}
</script>

</body>
</html>

Result

If HTML and JavaScript are selected:

HTML JavaScript

If no checkbox is selected:

No Skill Selected

Example 3: Checkbox Validation

<!DOCTYPE html>
<html>
<head>
<title>Checkbox Validation</title>
</head>
<body>

<input type="checkbox" id="terms">
I accept the Terms & Conditions
<br><br>

<button onclick="validateForm()">Register</button>

<script>
function validateForm() {

if(document.getElementById("terms").checked)
{
alert("Registration Successful");
}
else
{
alert("Please accept the Terms & Conditions.");
}

}
</script>

</body>
</html>

Result

Checkbox StatusOutput
✔ CheckedRegistration Successful
✘ Not CheckedPlease accept the Terms & Conditions.

These examples are suitable for beginners learning JavaScript and demonstrate how to read a checkbox's checked property, work with multiple checkboxes, and validate user input.

Example 2: Validate Name, Email, and Mobile Number

 <!DOCTYPE html>

<html>

<head>

<script>

function validate() {


    var name = document.getElementById("txtName").value;

    var email = document.getElementById("txtEmail").value;

    var mobile = document.getElementById("txtMobile").value;


    if (name == "") {

        alert("Please enter your name.");

        return;

    }


    if (email == "") {

        alert("Please enter your email.");

        return;

    }


    if (!email.includes("@")) {

        alert("Invalid Email Address.");

        return;

    }


    if (mobile.length != 10) {

        alert("Mobile number must be 10 digits.");

        return;

    }


    alert("Form Submitted Successfully!");

}

</script>

</head>


<body>


<h2>Student Registration</h2>


Name:

<input type="text" id="txtName"><br><br>


Email:

<input type="text" id="txtEmail"><br><br>


Mobile:

<input type="text" id="txtMobile"><br><br>


<button onclick="validate()">Submit</button>


</body>

</html>

Below is a simple example of saving data from HTML text boxes to a SQL Server database using HTML + jQuery + ASP.NET Web API (C#).

 Below is a simple example of saving data from HTML text boxes to a SQL Server database using HTML + jQuery + ASP.NET Web API (C#).

Note: jQuery cannot connect directly to SQL Server. It sends data to a server-side API, and the API inserts the data into SQL Server.


1. SQL Server Table

CREATE TABLE Student
(
StudentID INT IDENTITY(1,1) PRIMARY KEY,
Name NVARCHAR(100),
Email NVARCHAR(100),
Mobile NVARCHAR(15)
);

2. HTML

<!DOCTYPE html>
<html>
<head>
<title>Save Data</title>

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
</head>
<body>

<h2>Student Registration</h2>

Name :
<input type="text" id="txtName"><br><br>

Email :
<input type="text" id="txtEmail"><br><br>

Mobile :
<input type="text" id="txtMobile"><br><br>

<input type="button" id="btnSave" value="Save">

<div id="msg"></div>

<script>

$("#btnSave").click(function () {

var student = {
Name: $("#txtName").val(),
Email: $("#txtEmail").val(),
Mobile: $("#txtMobile").val()
};

$.ajax({
url: "/api/student/save",
type: "POST",
contentType: "application/json",
data: JSON.stringify(student),

success: function (response) {
$("#msg").html("Record Saved Successfully.");
},

error: function () {
$("#msg").html("Error while saving record.");
}
});

});

</script>

</body>
</html>

3. C# Model

public class Student
{
public string Name { get; set; }
public string Email { get; set; }
public string Mobile { get; set; }
}

4. Web API Controller

using System.Data.SqlClient;
using System.Configuration;
using System.Web.Http;

public class StudentController : ApiController
{
[HttpPost]
[Route("api/student/save")]

public IHttpActionResult Save(Student obj)
{
SqlConnection con = new SqlConnection(
ConfigurationManager.ConnectionStrings["dbcon"].ConnectionString);

SqlCommand cmd = new SqlCommand(
"INSERT INTO Student(Name,Email,Mobile) VALUES(@Name,@Email,@Mobile)", con);

cmd.Parameters.AddWithValue("@Name", obj.Name);
cmd.Parameters.AddWithValue("@Email", obj.Email);
cmd.Parameters.AddWithValue("@Mobile", obj.Mobile);

con.Open();
cmd.ExecuteNonQuery();
con.Close();

return Ok("Saved Successfully");
}
}

5. Web.config Connection String

<connectionStrings>
<add name="dbcon"
connectionString="Data Source=SERVERNAME;
Initial Catalog=CollegeDB;
Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>

How It Works

HTML TextBox


jQuery AJAX


ASP.NET Web API


SQL Server Database

Output

Suppose the user enters:

After clicking Save, the following record is inserted into SQL Server:

StudentIDNameEmailMobile
1Nilesh Guptanilesh@gmail.com9876543210

Gridview send email

 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; ...