Sunday, September 6, 2026

Saturday, September 5, 2026

GRIDVIEW DISPLAY TEXT IN PARAGRAPH

   <asp:TemplateField HeaderText="Message">


                      <ItemTemplate>


                        <div style=" width: 100%;

                                max-width: 900px;

                                font-size: 13px;

                                line-height: 1.7;

                                white-space: normal;

                                overflow-wrap: break-word;

                                word-wrap: break-word;

                                text-align: justify;">


                            <%# Eval("message") %> 


                        </div>


                          

                          

                    </ItemTemplate>


                 </asp:TemplateField>


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();

    }

ADD MP4 VIDEO IN ASPX PAGE

  <video autoplay loop muted width="100%" height="100%" src="pic/yoga.mp4"> x