Wednesday, December 20, 2023

GRIDVIEW ON ROW DATA BOUND EVENT

 Database Create 

Student : roll , name , city , cost 

Fix 6 Value  in Database Record 


====================================================================

Default.aspx Page 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="WebApplication1._default" %>


<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

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

OnRowDataBound = "OnRowDataBound" ShowFooter="True">

    <Columns>

        <asp:BoundField DataField="roll" HeaderText="Roll" ItemStyle-Width = "100">

<ItemStyle Width="100px"></ItemStyle>

        </asp:BoundField>

        <asp:BoundField DataField="name" HeaderText="Name" ItemStyle-Width = "100">


<ItemStyle Width="100px"></ItemStyle>

        </asp:BoundField>


        <asp:BoundField DataField="city" HeaderText="Name" ItemStyle-Width = "100">

<ItemStyle Width="100px"></ItemStyle>

        </asp:BoundField>

        <asp:TemplateField HeaderText="City">


            <ItemTemplate>




                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("cost") %>'></asp:TextBox>

            </ItemTemplate>



        </asp:TemplateField>

    </Columns>

</asp:GridView>

    </form>

</body>

</html>

=====================================================================


C#  Coading  Concept 

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;


namespace WebApplication1
{
    public partial class _default : System.Web.UI.Page
    {
        SqlConnection cn;
        SqlCommand cm;
        SqlDataReader dr;

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {

                display();
            }

        }



        protected void display()
        {

            string path = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\dell\Desktop\gridvcont\WebApplication1\WebApplication1\App_Data\Database1.mdf;Integrated Security=True";
            cn = new SqlConnection(path);
            cn.Open();


            string k = "select * from student";
            cm = new SqlCommand(k, cn);
            dr = cm.ExecuteReader();

            GridView1.DataSource = dr;
            GridView1.DataBind();

            dr.Close();



        }
        protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
        {

            
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                
                TextBox tb = (TextBox)e.Row.FindControl("TextBox1");

                 TableCell cell = e.Row.Cells[2];

                string cityname = cell.Text;

                if (cityname == "NAGPUR")
                {

                    tb.BackColor = System.Drawing.Color.Red;
                }

                
            }

           

        }

    }
}

Friday, November 24, 2023

JAVA SCRIPT PASS TEXTBOX DATA TO FUNCTION PARAMETER

 <html>

<head>

<script language="JavaScript">


function display(name,m1,m2)

{


var total;

total=parseInt(m1)+ parseInt(m2);

document.write(name + "<br>"  + total );


}


</script>



</head>


<body>


enter your name :  <input type="text" id="t1"> <br>


enter your m1:  <input type="text" id="t2"> <br>


enter your m2:  <input type="text" id="t3"> <br>


<input type="button" value="submit" onclick="display(document.getElementById('t1').value , document.getElementById('t2').value ,  document.getElementById('t3').value ,  )">


</body>

</html>

Friday, November 3, 2023

HOW TO SEND BILL FORMAT TO MAIL BODY

 STEP 1  CREATE PANEL CONTROL 


STEP 2  UNDER PANEL CONTROL CREATE ALL  FORM  AND DESIGN 


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>


<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    

        <asp:Button ID="Button1" runat="server" Text="SHOW DATA" Width="157px" OnClick="Button1_Click" />

        &nbsp;

        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="SEND MAIL" Width="161px" />

&nbsp;

       

        <br />

        <br />

        <br />

    

   

          <asp:Panel ID="pnlContents" runat="server" style="border-style: ridge;padding:10px;">


               <h1>Customer Generate Bill </h1> <br />

               <address>Narula Business Center , Near Lokmat Square </address>

               <br />

               <b>Mobile No. 8411064860</b>

              <hr />


              <asp:FormView ID="FormView1" runat="server">


                  <ItemTemplate>

                      &nbsp;Student&nbsp; Information Details

                      <br />

                      <br />

                      &nbsp;



                       <b>Name of Customer : </b> <asp:Label ID="Label1" runat="server" Text='<%# Eval("name") %>'></asp:Label> <br />


                        <b>Customer City  : </b> <asp:Label ID="Label2" runat="server" Text='<%# Eval("city") %>'></asp:Label> <br />




                  </ItemTemplate>


              </asp:FormView>


          </asp:Panel> 


    </form>

</body>

</html>


===================  C#  Coading  ========================


using System.Data.SqlClient;

using System.IO;

using System.Net.Mail;


Coding  for  send  button 

protected void Button2_Click(object sender, EventArgs e)

    {

        //mail


        using (StringWriter sw = new StringWriter())

        {

            using (HtmlTextWriter hw = new HtmlTextWriter(sw))

            {


                pnlContents.RenderControl(hw);

                StringReader sr = new StringReader(sw.ToString());


                SmtpClient smtpClient = new SmtpClient("nrsolution4u-student.com", 25);


                smtpClient.Credentials = new System.Net.NetworkCredential("contact@nrsolution4u-student.com", "password");

                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;


                MailMessage mailMessage = new MailMessage("contact@nrsolution4u-student.com", "nileshimp2015@gmail.com");

                mailMessage.Subject = "Domain Testing";

                mailMessage.Body = sw.ToString();



                mailMessage.IsBodyHtml = true;

                smtpClient.Send(mailMessage);

            }

        }


    }


=================== render  function important  =========================

 public override void VerifyRenderingInServerForm(Control control)
    {
        /* Verifies that the control is rendered */
    }









Friday, October 20, 2023

30. MVC ALL ACTION CONCEPT

 


100% Placement Training Program

 

Mr. Nilesh Gupta

Founder , NRsolution4u

https://nileshsir.com/

http://nrsolution4u.com/prayatn/

Submit Review

 

All Types Of Action Methods In ASP.NET MVC 5

 

Step-1 Create Controller  [ StudentController ]

Step-2 Create View Page [ Empty without Model ]

 

ViewResult - Represents HTML and markup.

Controller  Code

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

 

namespace WebApplication1.Controllers

{

    public class StudentController : Controller

    {

       

        public ViewResult Index()

        {

            ViewBag.ItemList = "Computer Shop Item List Page";

            return View();

        }

    }

}

 

Index.cshtml (View Page Code)

 

@{

    Layout = null;

}

 

<!DOCTYPE html>

 

<html><body>  @ViewBag.ItemList  </body> </html>

 

EmptyResult - Represents no result.

Note : Only change controller . Index.cshtml code as it is

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

 

namespace WebApplication1.Controllers

{

    public class StudentController : Controller

    {

 

        public EmptyResult Index()

        {

            ViewBag.ItemList = "Computer Shop Item List Page";

            return new EmptyResult();

        }

    }

}

Output: It will return a blank page with no result.

 

 

 

 

 

 

 

 

 

 

 

RedirectResult - Represents a redirection to a new URL.

Controller Code

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

 

namespace WebApplication1.Controllers

{

    public class StudentController : Controller

    {

 

        public RedirectResult Index()

        {

            //return Redirect("Home/Contact"); 

 

 

            return Redirect("http://nileshsir.com");

        }

    }

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

JsonResult - Represents a JavaScript Object Notation result that can be used in an AJAX application.

JSON Result returns simple text file format and key value pairs. Sometimes you may want to return data in JSON Format and that situation you JSONResult is the best option.

Controller Code

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

 

namespace WebApplication1.Controllers

{

    public class StudentController : Controller

    {

 

 

        public JsonResult Index()

        {

            Employee emp = new Employee() // class create inside controller

            {

                ID = "Emp23",

                Name = "Steven Clark",

                Mobile = "825415426"

            };

            return Json(emp, JsonRequestBehavior.AllowGet);

        }

 

 

 

        public class Employee

        {

            public string ID { get; set; }

            public string Name { get; set; }

            public string Mobile { get; set; }

        } 

 

 

    }

}

 

Output :  
{"ID":"Emp23","Name":"Steven Clark","Mobile":"825415426"}
 
 
 

JavaScriptResult - Represents a JavaScript script.

It returns java script that can be executed on the client browser. It sends javascript content in response to browser. This block allow you to execute java script on client at run time.

Controller Code

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

 

namespace WebApplication1.Controllers

{

    public class StudentController : Controller

    {

 

        public ActionResult Index()

        {

 

            return View();

        }

 

 

        [HttpGet]

        public JavaScriptResult WarningMessage()

        {

            var msg = "alert('Are you sure want to Continue?');";

            return new JavaScriptResult(){  Script = msg  };

        }

 

    }

}

 

 

 

 

 

 

 

 

Index.cshtml  Code

 

@{

    Layout = null;

}

 

<!DOCTYPE html>

 

<html>

<head>

    <meta name="viewport" content="width=device-width" />

    <title>Index</title>

 

 

    <script src="~/Scripts/jquery-1.10.2.js"></script>

   

    <script>

        $(document).ready(function () {

            $("button").click(function () {

                $.getScript("/Student/WarningMessage");

            });

        });

    </script>

 

</head>

<body>

    <div>

        @ViewBag.ItemList

    </div>

 

    <button>Show Message</button>

 

 </body>

</html>

 

ContentResult - Represents a text result.

It returns user-defined content type. It is useful when you want to send some plain text message to browser screen.

Controller Code

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

 

namespace WebApplication1.Controllers

{

    public class StudentController : Controller

    {

 

      

        public ContentResult Index()

        {

            return Content("Hello ASP.NET MVC 5");

        }

 

    }

}

 

INDEX.cshtml

 

@{

    Layout = null;

}

 

<!DOCTYPE html>

 

<html>

<head>

    <meta name="viewport" content="width=device-width" />

    <title>Index</title>

 

</head>

<body>

    <div>

        @ViewBag.ItemList

    </div>

 

</body>

</html>

 

 

FileResult - Represents a downloadable file (with the binary content).

It represents the content of the file.

Controller Code:

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

 

namespace WebApplication1.Controllers

{

    public class StudentController : Controller

    {

 

        public ActionResult Index()

        {

 

            return View();

 

        }

 

 

        [HttpGet]

        public FileResult Download()

        {

           

 

   byte[] fileBytes = System.IO.File.ReadAllBytes(@"D:\testdata\demo.txt");

           

   string filename = "demo.txt";

 

 

   return File(fileBytes, filename); // direct open file data

 

   return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, filename);  //download   file  in browser

 

        }

       }

}

 

 

 

 

 

Index.cshtml  code

 

 

@{

    Layout = null;

}

 

<!DOCTYPE html>

 

<html>

<head>

    <meta name="viewport" content="width=device-width" />

    <title>Index</title>

 

</head>

<body>

    <div>

        @ViewBag.ItemList

 

 

 

        @Html.ActionLink("Download Text File", "Download", "Student")

    </div>

 

   

 </body>

</html>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

PartialViewResult

 

Step 1: Add a partial page. Go to Solution Explorer SharedRight-click on it and select Add View.

 

 

 

Step 2: Create partial view page as described in this picture.

 

 

 

 

Step 3: Add the following code in message.cshtml page.

 

<h1> This is PartialViewResult Example Output. </h1>

 

 

Step 4 :  Controller  Code

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

 

namespace WebApplication1.Controllers

{

    public class StudentController : Controller

    {

 

 

        public ActionResult Index()

        {

            return View();

        }

 

        [HttpGet]

        public PartialViewResult messagepage()

        {

            return PartialView("message");

        }

      

  }

} 

 

 

 

 

 

 

 

 

 

 

 

 

 

Step -5   Index.cshtml  code

 

 

 

@{

    Layout = null;

   

}

 

<!DOCTYPE html>

 

<html>

<head>

    <meta name="viewport" content="width=device-width" />

    <title>Index</title>

 

</head>

<body>

    <div>

        @ViewBag.ItemList

 

 

 

        @{

            Html.RenderAction("messagepage", "Student");

          

        }

 

    </div>

 

   

 </body>

</html>

 

 

 

 

 

 

 

 

GRIDVIEW ON ROW DATA BOUND EVENT

 Database Create  Student : roll , name , city , cost  Fix 6 Value  in Database Record  ====================================================...