Tuesday, 26 July 2016

Adding gridview row values using viewstate and delete the temporary rows with conformation

Step 1 : Adding the two text box and one button and gridview  like below in your page.

Step 2: Add the code in aspx page.


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
        
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <br />
        <center>

        
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse">
        <tr>
            <td style="padding-bottom: 10px">
                Name:<br />
                <asp:TextBox ID="txtName" runat="server" />
            </td>
        </tr>
        <tr>
            <td style="padding-bottom: 10px">
                Country:<br />
                <asp:TextBox ID="txtCountry" runat="server" />
            </td>
        </tr>
        <tr>
            <td style="width: 100px">
                <asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="Insert" />
            </td>
        </tr>
    </table>
        <br />
        <asp:GridView ID="GridView1" runat="server" CssClass="Grid" AutoGenerateColumns="False"
        EmptyDataText="No records has been added." CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDeleting="OnRowDeleting" OnRowDataBound = "OnRowDataBound">
         <AlternatingRowStyle BackColor="White" />
         <Columns>
              <asp:CommandField ShowDeleteButton="True" ButtonType="Button" />
            <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="120" >
<ItemStyle Width="120px"></ItemStyle>
            </asp:BoundField>
            <asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="120" >
<ItemStyle Width="120px"></ItemStyle>
            </asp:BoundField>
        </Columns>
                      <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
         <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
         <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
         <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
         <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
         <SortedAscendingCellStyle BackColor="#FDF5AC" />
         <SortedAscendingHeaderStyle BackColor="#4D0000" />
         <SortedDescendingCellStyle BackColor="#FCF6C0" />
         <SortedDescendingHeaderStyle BackColor="#820000" />
                      </asp:GridView>
            </center>
    </form>
</body>
</html>

Step 2: Add the code in C#  page.

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

public partial class CS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Name"), new DataColumn("Country") });
            ViewState["jkt"] = dt;
            this.BindGrid();
        }
    }

    protected void BindGrid()
    {
        GridView1.DataSource = (DataTable)ViewState["jkt"];
        GridView1.DataBind();
    }

    protected void Insert(object sender, EventArgs e)
    {
        DataTable dt = (DataTable)ViewState["jkt"];
        dt.Rows.Add(txtName.Text.Trim(), txtCountry.Text.Trim());
        ViewState["jkt"] = dt;
        this.BindGrid();
        txtName.Text = string.Empty;
        txtCountry.Text = string.Empty;
    }
    protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int index = Convert.ToInt32(e.RowIndex);
        DataTable dt = ViewState["jkt"] as DataTable;
        dt.Rows[index].Delete();
        ViewState["jkt"] = dt;
        BindGrid();
    }

    protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string item = e.Row.Cells[0].Text;
            foreach (Button button in e.Row.Cells[0].Controls.OfType<Button>())
            {
                if (button.CommandName == "Delete")
                {
                    button.Attributes["onclick"] = "if(!confirm('Do you want to delete " + item + "?')){ return false; };";
                }
            }
        }
    }
}


Step 3: Run the page .




Step 4:Enter some values .


Step 5: Delete any one row .


Step 6: Click OK.





Step 7: Download the source code the given the below link .

Monday, 25 July 2016

Email Text Box with auto suggestion multiple email using Jquery :

Step 1:  Download CSS  & Jquery  file below link -



Step 2:  Create a new empty website -

Step 3:  Add new page and copy the downloaded files in your website -

Step 4:  Add the code below  -

<%@ 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>
    <link href="css/mailtip.css" rel="stylesheet" />
    <script src="qury/jquery-1.11.3.js"></script>
    <script src="qury/jquery.mailtip.js"></script>
    <style type="text/css">
        .styletxt {
            text-transform:lowercase;
            border-bottom-width:1px;
            font-family:'Times New Roman';
            font-size:larger;
            height:20px;
            width:200px;
           
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    <div class="box">
      <div><span >Enter Email Id:</span></div>
      <div>
          <asp:TextBox ID="mailtip" CssClass="styletxt" runat="server" Height="21px" Width="211px"></asp:TextBox>
    </div>
      </div>
    </div>
    <script type="text/javascript">
        $(function () {
            var info = $('.info');

            $('#mailtip').mailtip({
                onselected: function (mail) {
                    info.text('you choosed email: ' + mail)
                }
            });
        });
    </script>
       
    </form>
</body>
</html>


Step 5: Run the page  -

Step 6:  Add the code below  -

Normal text box  :

Auto suggestion email textbox :



Step 5: Download source code and all files below link -







Thursday, 7 July 2016

Auto Calculate (Sum) Bound Field Dynamic Gridview columns values and result shows Text Box or Label :

 Step 1: Add Text Box changed event in code behind page.       

 ontextchanged="TextBox1_TextChanged"
   

Step 2: Add code in your C#  page.

   protected void TextBox1_TextChanged(object sender, EventArgs e)

    {

        double total = 0;

             foreach (GridViewRow gvr in Gridview1.Rows)

        {

            TextBox tb = (TextBox)gvr.Cells[5].FindControl("Column1");

//Add column name insted of Column1 and Enter column cell index correctly.

            double sum;

            if (double.TryParse(tb.Text.Trim(), out sum))

            {

                total += sum;

            }

                   }

        totltxt.Text = total.ToString();

//You want to display label or textbox .

    }    


Step 3: Screen Shot.




    

Tuesday, 5 July 2016

Text highlighting using CSS on selection (Instead of blue color):

Step 1: Add the style in your web page head section . Its highlighted all texts.

<style type="text/css">
   
    ::selection {background:transparent; text-shadow:#000 0 0 2px;}
::-moz-selection {background:transparent; text-shadow:#000 0 0 2px;}
::-webkit-selection {background:transparent; text-shadow:#000 0 0 2px;}
::-o-selection {background:transparent; text-shadow:#000 0 0 2px;}
a object {background:#000;}
</style>

For Example:


<%@ 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>
    <style type="text/css">

    
    ::selection {background:transparent; text-shadow:#000 0 0 2px;}
::-moz-selection {background:transparent; text-shadow:#000 0 0 2px;}
::-webkit-selection {background:transparent; text-shadow:#000 0 0 2px;}
::-o-selection {background:transparent; text-shadow:#000 0 0 2px;}
a object {background:#000;}
        </style>
</head>
<body>
    <form id="form1" runat="server">
    <div style="text-align:left">
        

        <p>
            CSS is designed primarily to enable the separation of document content from document presentation, 
            including aspects such as the layout, colors, and fonts.[3] This separation can improve content accessibility, 
            provide more flexibility and control in the specification of presentation characteristics, enable multiple HTML pages to share 
            formatting by specifying the relevant CSS in a separate .css file, and reduce complexity and repetition in the structural content.
        </p>
        
    </div>
    </form>
</body>
</html>

Screen Shots:

Normal :



After applying CSS:





Tuesday, 21 June 2016

Display Error Message using Script Manager:

Step 1 : Add the code in your c# page.

 ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertmessage", "alert('Your alert message')", true);


Step 2: Output.

How to add Ajax Control Toolkit to Asp .Net Project

Step 1: First you need to download "AjaxControlToolkit.Binary.NET4.zip" .

https://ajaxcontroltoolkit.codeplex.com/downloads/get/608573

(If this link not working ,Search google "AjaxControlToolkit.Binary.NET4" and download it.File Size 7 MB approx)

Extract zip file.

Step 2: After downloading the file. Add reference to your project.

i)Right click the Solution Explorer and Add Reference.


ii) Browse extracted file and select "AjaxControlToolkit.dll".



iii) After open the project file adding  automatically Bin folder if it is not exists.

 

iv) Add the toolbox menu. Right click and add new tab 'ajax'. Then right click the ajax tab select Choose Items.

   

v) An window will pop up . Select Browse.


vi) Browse the same extracted file and select "AjaxControlToolkit.dll".


vii) After adding it shows.And clik ok.



viii) Now the ajax tab in the tool box. Contains the options are.


Step 3:Add the new text box in your project.



Step 4:Right click the top right corner .Select Add Extender.An window will be open.And select the Auto complete Extender or Calender Extender like any.



Step 5: The code behind page seems.


Step 6: Differents below. 

Normal Text Box.


Text Box with Ajax Extender.


Step 7 : Output.

Code Behind page: 


C# page :


O/P :

Monday, 20 June 2016

Auto Complete Text box using Ajax Auto Complete Extender and Retrieve the Database Column Values:

Step 1 : In your code behind page  add ajax register tag like below. 

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

          

Step 2 :Add ajax tool kit reference both Solution Explorer and Tool Box in your project.

Step 3: Add the text box in your page.


 <asp:TextBox ID="txtdepname" runat="server" Width="175px" Height="25px"></asp:TextBox>

                <asp:AutoCompleteExtender ID="txtdepname_AutoCompleteExtender" runat="server" MinimumPrefixLength="1" CompletionSetCount="10"

                    DelimiterCharacters="" Enabled="True" ServiceMethod="GetCity" TargetControlID="txtdepname" ServicePath="">

                </asp:AutoCompleteExtender>



step 4: You need to database and table with values .

step 5: C# page contains the code below.


[System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public static List<string> GetCity(string prefixText, int count)
    {

        MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["constr1"].ConnectionString);
        MySqlCommand cmdsur = new MySqlCommand("select distinct empname from empwork where " + "empname like '" + prefixText + "%'", con);
        cmdsur.Connection = con;
        con.Open();
        List<string> name = new List<string>();
        MySqlDataReader sdr = cmdsur.ExecuteReader();

        while (sdr.Read())
        {
            name.Add(sdr["empname"].ToString());
        }
        sdr.Close();
        con.Close();
        return name;
    }


Step 6: Output

Tuesday, 5 April 2016

Adding temporary values from multiple textbox to gridview and multi rows inserted to database.

Screen Shot 1:



Screen Shot 2:


Screen Shot 3:


aspx code:



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

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />

    <style type="text/css">
        .style2
        {
            border: 1px solid black;
            margin-left: 0px;
            margin-top: 6px;
            margin-bottom: 0px;
        }
        .style3
        {
            color: #CC0000;
        }
        .style4
        {
            color: #000099;
        }
        .style5
        {
            width: 262px;
        }
        .style6
        {
            height: 33px;
        }
        .style7
        {
            width: 262px;
            height: 33px;
        }
    </style>

    <style type="text/css">
        :focus {
        background-color:white;

        }

    </style>
   
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <Triggers>
    <asp:PostBackTrigger ControlID="printbtn" />
           
            </Triggers>
    <ContentTemplate>
    
    <h3></h3>
     <table style="width:1060px" >
        <tr style="background-color: #FFFFFF">
        <td align="right"><span style="color: #FF6600; font-size: large;">Login Name:&nbsp;&nbsp;&nbsp;</span></td>
        <td>
            <asp:Label ID="username" runat="server" CssClass="style4" ForeColor="#FF6600"></asp:Label>
            </td>
        <td align="right"><span style="color: #FF6600">Organization Name:</span></td>
        <td>
            <asp:Label ID="ddlorgname" runat="server" CssClass="style4" ForeColor="#FF6600"></asp:Label>
            </td>
        </tr>
        </table>
           <center><h3>GRN</h3></center>
<div>
<fieldset><legend>GRN</legend>
<table class="projecttable1" style="width:100%;">
<tr><td class="style3"><strong>GRN NUMBER</strong></td><td>
    <asp:Label ID="Label1" runat="server" style="color: #CC0000; font-weight: 700;"></asp:Label>
    </td><td>
        &nbsp;</td><td>
        &nbsp;</td><td>&nbsp;</td><td class="style5">
    &nbsp;</td><td>
        &nbsp;</td><td>&nbsp;</td></tr>
    <tr>
        <td>
            Date:</td>
        <td>
            <asp:TextBox ID="Txtdate" runat="server" CssClass="textbox" Height="25px" 
                Width="200px" AutoPostBack="True"></asp:TextBox>
            <asp:CalendarExtender ID="Txtdate_CalendarExtender" runat="server" 
                Enabled="True" Format="dd-MM-yyyy" TargetControlID="Txtdate">
            </asp:CalendarExtender>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                ControlToValidate="Txtdate" CssClass="style3" ErrorMessage="*" 
                style="font-weight: 700" ValidationGroup="G1"></asp:RequiredFieldValidator>
        </td>
        <td>
            &nbsp;</td>
        <td>
            CustomerName</td>
        <td class="style5">
            <asp:DropDownList ID="deptdrop" runat="server" AutoPostBack="True" 
                CssClass="style2" Height="25px" Width="200px">
            </asp:DropDownList>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" 
                ControlToValidate="deptdrop" CssClass="style3" ErrorMessage="*" 
                InitialValue="0" style="font-weight: 700" ValidationGroup="G1"></asp:RequiredFieldValidator>
        </td>
        <td>
            &nbsp;</td>
    </tr>
<tr><td class="style4">Problem.Material Name</td><td>
    <asp:TextBox ID="pmetxt" runat="server" TextMode="MultiLine" 
        CssClass="textbox" Height="52px" Width="197px"></asp:TextBox></td>
    <td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
            ControlToValidate="pmetxt" CssClass="style3" ErrorMessage="*" 
            style="font-weight: 700" ValidationGroup="G1"></asp:RequiredFieldValidator>
    </td>
    <td>
        &nbsp;</td>
    <td class="style4">Problem.Material 
        .Model.No</td><td class="style5">
    <asp:TextBox ID="pmetmonotxt" runat="server" CssClass="textbox" Height="25px" 
            Width="200px"></asp:TextBox></td><td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" 
            ControlToValidate="pmetmonotxt" CssClass="style3" ErrorMessage="*" 
            style="font-weight: 700" ValidationGroup="G1"></asp:RequiredFieldValidator>
    </td><td>&nbsp;</td></tr>
<tr><td class="style4">Problem.Material .S.No</td><td>
    <asp:TextBox ID="pmsnotxt" runat="server" CssClass="textbox" Height="25px" 
        Width="200px"></asp:TextBox></td>
    <td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
            ControlToValidate="pmsnotxt" CssClass="style3" ErrorMessage="*" 
            style="font-weight: 700" ValidationGroup="G1"></asp:RequiredFieldValidator>
    </td>
    <td>
        &nbsp;</td>
    <td class="style4">Problem</td><td class="style5">
    <asp:TextBox ID="prodettxt" runat="server" TextMode="MultiLine" 
        CssClass="textbox" Height="52px" Width="197px"></asp:TextBox></td><td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" 
            ControlToValidate="prodettxt" CssClass="style3" ErrorMessage="*" 
            style="font-weight: 700" ValidationGroup="G1"></asp:RequiredFieldValidator>
    </td><td>&nbsp;</td></tr>
    <tr>
        <td class="style4">
            Material Recive Date
        </td>
        <td>
            <asp:TextBox ID="datetimetxt" runat="server" CssClass="style2" Height="25px" 
                Width="200px"></asp:TextBox>
            <asp:CalendarExtender ID="datetimetxt_CalendarExtender" runat="server" 
                Enabled="True" Format="dd-MM-yyyy" TargetControlID="datetimetxt">
            </asp:CalendarExtender>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator14" runat="server" 
                ControlToValidate="datetimetxt" CssClass="style3" ErrorMessage="*" 
                InitialValue="0" style="font-weight: 700" ValidationGroup="G1"></asp:RequiredFieldValidator>
        </td>
        <td>
            &nbsp;</td>
        <td class="style4">
            &nbsp;</td>
        <td class="style5">
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
<tr><td>Stand By</td><td>
    <asp:DropDownList ID="standbydrop" runat="server" CssClass="style2" 
        Height="25px"
        Width="200px" onselectedindexchanged="standbydrop_SelectedIndexChanged" 
        AutoPostBack="True">
    <asp:ListItem Value="0">--Select--</asp:ListItem>
    <asp:ListItem Value="Y">Yes</asp:ListItem>
    <asp:ListItem Value="N">No</asp:ListItem>
    </asp:DropDownList>
    </td><td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
            ControlToValidate="standbydrop" CssClass="style3" ErrorMessage="*" 
            InitialValue="0" style="font-weight: 700" ValidationGroup="G1"></asp:RequiredFieldValidator>
    </td><td>
        &nbsp;</td><td>&nbsp;</td><td class="style5">
        &nbsp;</td><td>
        &nbsp;</td><td>&nbsp;</td></tr>
<tr id="stnd" runat="server" visible="false"><td class="style3">Replace Material Name</td><td>
                    <asp:TextBox ID="rmnametxt" runat="server" CssClass="textbox" Height="52px" 
                        TextMode="MultiLine" Width="197px"></asp:TextBox>
    </td><td>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
                        ControlToValidate="rmnametxt" CssClass="style3" ErrorMessage="*" 
                        style="font-weight: 700" ValidationGroup="G1"></asp:RequiredFieldValidator>
    </td><td>
                    &nbsp;</td><td class="style3">Model No</td><td class="style5">
                    <asp:TextBox ID="repmodnotxt" runat="server" CssClass="textbox" Height="25px" 
                Width="200px"></asp:TextBox>
                </td><td>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" 
                        ControlToValidate="repmodnotxt" CssClass="style3" ErrorMessage="*" 
                        style="font-weight: 700" ValidationGroup="G1"></asp:RequiredFieldValidator>
                </td><td>&nbsp;</td></tr>
<tr id="stnd1" runat="server" visible="false"><td class="style3">S.No</td><td>
                    <asp:TextBox ID="rmetsnotxt" runat="server" CssClass="textbox" Height="25px" 
            Width="200px"></asp:TextBox>
    </td><td>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" 
                        ControlToValidate="rmetsnotxt" CssClass="style3" ErrorMessage="*" 
                        style="font-weight: 700" ValidationGroup="G1"></asp:RequiredFieldValidator>
    </td><td>
                    &nbsp;</td><td class="style3">Material Reference No</td><td class="style5">
        <asp:TextBox ID="matnotxt" runat="server"  CssClass="textbox" Height="25px" 
            Width="200px" ontextchanged="txtmatno_TextChanged"  AutoPostBack="true" ></asp:TextBox>
    </td><td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator15" runat="server" 
            ControlToValidate="matnotxt" ErrorMessage="*" ValidationGroup="G1" ForeColor="#CC0000"></asp:RequiredFieldValidator>
    </td><td>&nbsp;</td></tr>
<tr><td>StaffName</td><td>
    <asp:DropDownList ID="staffdrop" runat="server" Height="25px" Width="200px" 
        CssClass="style2" AutoPostBack="True">
    </asp:DropDownList>
    </td><td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" 
            ControlToValidate="staffdrop" CssClass="style3" ErrorMessage="*" 
            InitialValue="0" style="font-weight: 700" ValidationGroup="G1"></asp:RequiredFieldValidator>
    </td><td>
        &nbsp;</td><td>
        &nbsp;</td><td class="style5">
        <asp:Label ID="lbler" runat="server" ForeColor="#CC0000" Text="Label"></asp:Label>
    </td><td>
        &nbsp;</td><td>&nbsp;</td></tr>
    <tr>
        <td>
            &nbsp;</td>
        <td align="right">
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td align="center">
            <asp:Button ID="addbtn" runat="server" onclick="addbtn_Click" style="font-size: large" Text="Add" 
                ValidationGroup="G1" Width="89px" Height="40px" />
        </td>
        <td class="style5">
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
<tr id="retun" runat="server" visible="false"><td>Reparing Status</td><td>
    <asp:TextBox ID="repairtxt" runat="server" TextMode="MultiLine" 
        CssClass="textbox" Height="52px" Width="197px"></asp:TextBox></td><td>
        &nbsp;</td><td>
        &nbsp;</td><td>Return Details</td><td class="style5">
    <asp:TextBox ID="retdettxt" runat="server" TextMode="MultiLine" 
        CssClass="textbox" Height="52px" Width="197px"></asp:TextBox></td><td>
        &nbsp;</td><td>&nbsp;</td></tr>
<tr id="retun1" runat="server" visible="false"><td class="style6">&nbsp;</td><td class="style6">
            &nbsp;</td><td class="style6">
            &nbsp;</td><td class="style6">
            &nbsp;</td><td class="style6">
        &nbsp;</td><td class="style7">
        </td><td class="style6">
        </td><td class="style6"></td></tr>
<tr><td align="center" colspan="6">
    &nbsp;</td><td align="center">&nbsp;</td><td>&nbsp;</td></tr>
</table>
</fieldset>
<div>

    <asp:GridView ID="stockgrid" runat="server" AutoGenerateDeleteButton="True">
    </asp:GridView>

</div>
<br />
<center>
<div>
    <asp:Button ID="savebtn" runat="server" Height="39px" onclick="savebtnn_Click" 
        style="font-size: large" Text="Save" Width="93px" />
    <asp:Label ID="lblmain" runat="server"></asp:Label>

    <asp:Button ID="printbtn" style="font-size: large" runat="server" Height="40px" Text="Print" 
        Width="95px" onclick="printbtn_Click" />

</div>
</center>
<br />
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
        AutoDataBind="true" />
<br />
    <br />
</div>
</ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>



C# Code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.IO;
using System.Net;
using System.Data;
using MySql.Data.MySqlClient;
using System.Globalization;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
public partial class grn : System.Web.UI.Page
{
    string createdon;
    string ipaddr;
    DataTable tbs = new DataTable();
    DataRow drow;
    protected void Page_Load(object sender, EventArgs e)
    {
        lbler.Visible = false;
        string strHostName = null;
        strHostName = System.Net.Dns.GetHostName();
        ipaddr = System.Net.Dns.GetHostEntry(strHostName).AddressList[0].ToString();
        ddlorgname.Text = Session["location"].ToString();
        createdon = DateTime.Now.ToString("yyyy-MM-dd");
        username.Text = Session["user"].ToString();
        Txtdate_CalendarExtender.StartDate = DateTime.Now;

        if (!IsPostBack)
        {
            staff();
            dept();
            create_table();
            Txtdate.Focus();
            savebtn.Visible = false;
            printbtn.Visible = false;
        }
    }
    protected void standbydrop_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (standbydrop.Text == "Y")
        {
            stnd.Visible = true;
            stnd1.Visible = true;
        }
        else
        {
            stnd.Visible = false;
            stnd1.Visible = false;

        }
    }

    public void staff()
    {
        string connString = ConfigurationManager.ConnectionStrings["constr1"].ConnectionString;
        MySqlConnection myConnection = new MySqlConnection(connString);
        myConnection.Open();
        MySqlCommand cmd = new MySqlCommand("select staffname,loginname from volsstaff order by staffname asc", myConnection);
        MySqlDataAdapter ad = new MySqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        ad.Fill(ds);

        staffdrop.DataSource = ds;
        staffdrop.DataTextField = "staffname";
        staffdrop.DataValueField = "loginname";
        staffdrop.DataBind();
        staffdrop.Items.Insert(0, new ListItem("--Select--", "0"));
        myConnection.Close();
    }
    public void dept()
    {
        string connString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        MySqlConnection myConnection = new MySqlConnection(connString);
        myConnection.Open();
        MySqlCommand cmdqw = new MySqlCommand("select  departmentname from dept where orgname='" + ddlorgname.Text + "' or departmentname='Others' order by departmentname asc", myConnection);

        MySqlDataAdapter adap = new MySqlDataAdapter(cmdqw);
        DataSet ds = new DataSet();
        adap.Fill(ds);
        deptdrop.DataSource = ds;
        deptdrop.DataTextField = "departmentname";
        //ddlrack.DataValueField = "uniqueboxcode";
        deptdrop.DataBind();
        deptdrop.Items.Insert(0, new ListItem("--Select--", "0"));
        myConnection.Close();
    }
  
    public void createtablecategory()
    {


    }
    protected void create_table()
    {
        tbs.Columns.Add("Date", typeof(string));
        tbs.Columns.Add("Customer Name", typeof(string));
        tbs.Columns.Add("Problem.Material Name", typeof(string));
        tbs.Columns.Add("Problem.Material .Model.No", typeof(string));
        tbs.Columns.Add("Problem.Material .S.No", typeof(string));
        tbs.Columns.Add("Problem", typeof(string));
        tbs.Columns.Add("Stand By", typeof(string));
        tbs.Columns.Add("Replace Material Name", typeof(string));
        tbs.Columns.Add("Model No", typeof(string));
        tbs.Columns.Add("S.No", typeof(string));
        tbs.Columns.Add("StaffName", typeof(string));
        tbs.Columns.Add("Material Recive Date", typeof(string));
        tbs.Columns.Add("Reference ID", typeof(string));
        //tbs.Columns.Add("Reparing Status", typeof(string));
        //tbs.Columns.Add("Return Details", typeof(string));
        //tbs.Columns.Add("Date ", typeof(string));
        stockgrid.DataSource = tbs;
        stockgrid.DataBind();
        ViewState["stockdetails"] = tbs;
    }
    protected void addbtn_Click(object sender, EventArgs e)
    {
        tbs = (DataTable)ViewState["stockdetails"];
        drow = tbs.NewRow();
        drow["Date"] = Txtdate.Text;
        drow["Customer Name"] = deptdrop.SelectedItem.ToString();
        drow["problem.Material Name"] = pmetxt.Text;
        drow["Problem.Material .Model.No"] = pmetmonotxt.Text;
        drow["Problem.Material .S.No"] = pmsnotxt.Text;
        drow["Problem"] = prodettxt.Text;
        drow["Stand By"] = standbydrop.SelectedItem.Text;
        drow["Replace Material Name"] = rmnametxt.Text;
        drow["Model No"] = repmodnotxt.Text;
        drow["S.No"] = rmetsnotxt.Text;
        drow["StaffName"] = staffdrop.SelectedItem.ToString();
        drow["Material Recive Date"] = datetimetxt.Text;
        drow["Reference ID"] = matnotxt.Text;
                //    drow["Return Details"]=retdettxt.Text;
        //        drow["Date"]=
        tbs.Rows.Add(drow);
        stockgrid.DataSource = tbs;
        stockgrid.DataBind();
        Txtdate.Text = "";
        deptdrop.SelectedValue = "0";
        pmetxt.Text = "";
        pmetmonotxt.Text = "";
        pmsnotxt.Text = "";
        prodettxt.Text = "";
        datetimetxt.Text = "";
        standbydrop.SelectedValue = "0";
        rmnametxt.Text = "";
        repmodnotxt.Text = "";
        rmetsnotxt.Text = "";
        staffdrop.SelectedValue = "0";
        repairtxt.Text = "";
        retdettxt.Text = "";
        matnotxt.Text = "";
        savebtn.Visible = true;
        printbtn.Visible = true;
    }
    protected void printbtn_Click(object sender, EventArgs e)
    {
        string connString = ConfigurationManager.ConnectionStrings["constr1"].ConnectionString;
        MySqlConnection myConnection = new MySqlConnection(connString);
        myConnection.Open();
        MySqlCommand cmd12p = new MySqlCommand("select grnno,grnumber,DATE_FORMAT(grndate, '%m-%d-%Y') AS 'grndate',deptname,upper(CONCAT_ws('',pmdetails,'/ ',pmmno,'/ ',pmsno))  'pmdetails',problem,upper(CONCAT_ws('',rmdetails,'/ ',rmmno,'/ ',rmsno)) 'rmdetails',staffname,role,COALESCE(printon, '" + createdon + "') 'printon',COALESCE(printby, '" + username.Text + "') 'printby',COALESCE(printat, '" + ipaddr + "') 'printat' from grntable where grnumber='" + Label1.Text + "' and fflag='N'", myConnection);
        MySqlDataAdapter da12p = new MySqlDataAdapter(cmd12p);
        DataSet ds12p = new DataSet();
        da12p.Fill(ds12p);
        ReportDocument rddp = new ReportDocument();
        rddp.Load(Server.MapPath(@"crystalreport.rpt"));
        rddp.SetDataSource(ds12p.Tables[0]);
        CrystalReportViewer1.ReportSource = rddp;
        myConnection.Close();
        rddp.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "EXPORTEDREPORT");
    }
    protected void txtmatno_TextChanged(object sender, EventArgs e)
    {
        if (Page.IsPostBack == true)
        {

        string connString = ConfigurationManager.ConnectionStrings["constr1"].ConnectionString;
        MySqlConnection myConnection = new MySqlConnection(connString);

        using (var cmd = new MySqlCommand("select matno from sbm where matno=@matno", myConnection))
        {
            myConnection.Open();

            cmd.Parameters.AddWithValue("@matno", matnotxt.Text);
            using (var dr = cmd.ExecuteReader())
            {
                if (dr.HasRows)
                {
                    //lbler.Visible = true;
                    //lbler.Text = "already exists";
                }
                else
                {
                    lbler.Visible = true;
                    lbler.Text = "doesn't exists";

                }

            }
        }

        myConnection.Close();

    }
}
    protected void savebtnn_Click(object sender, EventArgs e)
    {
        
        string grno, cname, pmdet, pmmno, pmsno, problem, standby, rmdet, rmmno, rmsno, staffname, referenceid;

    string connString = ConfigurationManager.ConnectionStrings["constr1"].ConnectionString;
    MySqlConnection myConnection = new MySqlConnection(connString);
    myConnection.Open();
    MySqlTransaction tran = myConnection.BeginTransaction();
    try
    {
        MySqlCommand cmd89 = new MySqlCommand("select count(*) from grnno", myConnection);
        int count = Convert.ToInt32(cmd89.ExecuteScalar());
        if (count == 0)
        {
            grno = "GRNR-1001";
        }
        else
        {
            int dg = count + 1 + 1000;
            grno = "GRNR-" + dg.ToString();
        }
        for (int i = 0; i < stockgrid.Rows.Count; i++)
        {
            string sdate = stockgrid.Rows[i].Cells[1].Text;
            DateTime recdt = DateTime.ParseExact(sdate, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            string dates = recdt.ToString("yyyy-MM-dd");
            cname = stockgrid.Rows[i].Cells[2].Text;
            pmdet = stockgrid.Rows[i].Cells[3].Text;
            pmmno = stockgrid.Rows[i].Cells[4].Text;
            pmsno = stockgrid.Rows[i].Cells[5].Text;
            problem = stockgrid.Rows[i].Cells[6].Text;
            standby = stockgrid.Rows[i].Cells[7].Text;
            rmdet = stockgrid.Rows[i].Cells[8].Text;
            rmmno = stockgrid.Rows[i].Cells[9].Text;
            rmsno = stockgrid.Rows[i].Cells[10].Text;
            staffname = stockgrid.Rows[i].Cells[11].Text;
            string sdate1 = stockgrid.Rows[i].Cells[12].Text;
            referenceid = stockgrid.Rows[i].Cells[13].Text;
            DateTime recdt1 = DateTime.ParseExact(sdate1, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            string dates1 = recdt.ToString("yyyy-MM-dd");
            MySqlCommand cmd = new MySqlCommand("insert into grntable(grnumber,grndate,deptname,pmdetails,pmmno,pmsno,standby,rmdetails,rmmno,rmsno,staffname,createdon,createdby,createdat,problem,role,promatrcvdate,trackitem,referenceid)values('" + grno + "','" + dates + "','" + cname + "','" + pmdet + "','" + pmmno + "','" + pmsno + "','" + standby + "','" + rmdet + "','" + rmmno + "','" + rmsno + "','" + staffname + "','" + createdon + "','" + username.Text + "','" + ipaddr + "','" + problem + "','" + ddlorgname.Text + "','" + dates1 + "','GRC','" + referenceid + "')", myConnection, tran);
            cmd.ExecuteNonQuery();

        }
        MySqlCommand cmd87 = new MySqlCommand("insert into grnno(date)values('" + createdon + "')", myConnection, tran);
        cmd87.ExecuteNonQuery();
        tran.Commit();
        Label1.Text = grno;
        lblmain.Visible = true;
        lblmain.Text = "GRN Submited Sucessfully";

        myConnection.Close();

    }
    catch (Exception)
    {
        tran.Rollback();
        lblmain.Visible = true;
        lblmain.Text = "GRN Submited Failed";
        myConnection.Close();
    }
}

    }


    





How to create a simple Hello World website in ASP.NET MVC using Razor Syntax: (Note: I am using Visual Studio 2012 ) Step 1: ...