Sunday, 11 November 2012

Simple Ajax Model Popup In Asp.net

Don't forget to add AjaxControlTool Kit ...then follow this code ..

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

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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">
        .modalBackground
        {
            background-color: #D65C33;
            filter: alpha(opacity=180);
            opacity: 0.8;
        }
        .modalPopup
        {
            background-color: #FFFFFF;
            border-width: 3px;
            border-style: solid;
            border-color: black;
            padding-top: 10px;
            padding-left: 10px;
            width: 300px;
            height: 140px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="SM" runat="server">
        </asp:ScriptManager>
        <asp:Button ID="btnShow" runat="server" Text="Show Modal Popup" title="Click to show popup"
            OnClick="btnShow_Click" />
        <cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel" TargetControlID="btnShow"
            CancelControlID="imgclose" BackgroundCssClass="modalBackground">
        </cc1:ModalPopupExtender>
        <asp:Panel ID="Panel" runat="server" CssClass="modalPopup" align="center" BorderColor="#000099"
            BorderWidth="5px" Style="display: none">
            <asp:Image runat="server" ID="imgclose" ImageUrl="~/download.jpg" Style="margin-left: 260px;"
                title="Close" />
            <asp:Label runat="server" ID="lblPop" Text="This is Ajax Model Popup Created By Sajil"></asp:Label>
        </asp:Panel>
    </div>
    </form>
</body>
</html>



Highlight asp.net gridview rows on mouseover using JavaScript

Here I  explained  how to highlight grid view rows based on mouse over and mouse out using JavaScript in asp.net.
Create Database SampleDatabase;
create table Employee
(
RowId int Primary key identity(1,1),
EmpId int ,
EmpNam Varchar(50),
Empdesig varchar(50),
EmpGender Varchar(10),
Empcity Varchar(30),
EmpState Varchar(30),
EmpCountry Varchar(30),
EmpSalary int,
EmpDoj varchar(50)
)
insert into employee values(1000,'sajil','S/W Engineer','Male','Chennai','TamilNadu','India',10000,'10/12/2012')
insert into employee values(1002,'sanil','IQC','Male','Chennai','TamilNadu','India',6000,'05/12/2012')
insert into employee values(1003,'vino','Manager','Male','Chennai','TamilNadu','India',16000,'05/12/2012')
insert into employee values(1004,'viji','supervisor','Female','Chennai','TamilNadu','India ',5000, '07/11/2012')
insert into employee values(1005,'vimal','S/W Engineer','Male','Chennai','TamilNadu','India',6000,'09/11/2012')

Aspx Page<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HighlightGridRow.aspx.cs"
    Inherits="HighlightGridRow" %>
<!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>
    <script type="text/javascript">
        var oldgridcolor;
        function SetMouseOver(element) {
            oldgridcolor = element.style.backgroundColor;
            element.style.backgroundColor = '#B2C2D1';
     
         
        }
        function SetMouseOut(element) {
            element.style.backgroundColor = oldgridcolor;
            element.style.textDecoration = 'none';
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            <asp:GridView runat="server" ID="gvrecords" AutoGenerateColumns="False" HeaderStyle-BackColor="#7779AF"
                HeaderStyle-ForeColor="White" OnRowDataBound="gvrecords_RowDataBound"
                BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
                CellPadding="4">
                <Columns>
                    <asp:BoundField DataField="EmpId" HeaderText="EmployeeId" />
                    <asp:BoundField DataField="EmpNam" HeaderText="EmployeeName" />
                    <asp:BoundField DataField="Empdesig" HeaderText="EmployeeDesignation" />
                    <asp:BoundField DataField="EmpGender" HeaderText="EmployeeGender" />
                    <asp:BoundField DataField="Empcity" HeaderText="EmployeeCity" />
                    <asp:BoundField DataField="EmpState" HeaderText="EmployeeState" />
                    <asp:BoundField DataField="EmpCountry" HeaderText="EmployeeCounty" />
                    <asp:BoundField DataField="EmpSalary" HeaderText="EmployeeSalary" />
                    <asp:BoundField DataField="EmpDoj" HeaderText="EmployeeDOJ" />
                </Columns>
                <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" ForeColor="#CCCCFF" Font-Bold="True"></HeaderStyle>
                <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
                <RowStyle BackColor="White" ForeColor="#003399" />
                <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                <SortedAscendingCellStyle BackColor="#EDF6F6" />
                <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
                <SortedDescendingCellStyle BackColor="#D6DFDF" />
                <SortedDescendingHeaderStyle BackColor="#002876" />
            </asp:GridView>
        </div>
    </div>
    </form>
</body>
</html>
Cs Pageusing 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.Data;
using System.Configuration;
public partial class HighlightGridRow : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString());
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridview();
        }
    }
    protected void gvrecords_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onmouseover"] = "javascript:SetMouseOver(this)";
            e.Row.Attributes["onmouseout"] = "javascript:SetMouseOut(this)";
        }
    }
    protected void BindGridview()
    {
     
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from Employee", con);
        cmd.ExecuteNonQuery();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        gvrecords.DataSource = ds;
        gvrecords.DataBind();
    }
}

Friday, 2 November 2012

Currecy format in textbox using java script


here the code for that....
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Currencyformat.aspx.cs" Inherits="Currencyformat" %>

<!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>
    <script type="text/javascript">
function MaskMoney1(evt, allow) {

            if (!(evt.keyCode == 46 || (evt.keyCode >= 48 && evt.keyCode <= 57))) return false;
            var parts = evt.srcElement.value.split('.');
            if (parts.length > 2) return false;
            if (evt.keyCode == 46) return (parts.length == 1);
            if (parts[0].length >= 14) return false;
            if (parts.length == 2 && parts[1].length >= allow) return false;
        }


    function insertcommas(nField) {
        if (/^0/.test(nField.value)) {
            nField.value = nField.value.substring(0, 1);
        }
        if (Number(nField.value.replace(/,/g, ""))) {
            var tmp = nField.value.replace(/,/g, "");
            tmp = tmp.toString().split('').reverse().join('').replace(/(\d{3})/g, '$1,').split('').reverse().join('').replace(/^,/, '');
            if (/\./g.test(tmp)) {
                tmp = tmp.split(".");
                tmp[1] = tmp[1].replace(/\,/g, "").replace(/ /, "");
                nField.value = tmp[0] + "." + tmp[1]
            }
            else {
                nField.value = tmp.replace(/ /, "");
            }
        }
        else {
            nField.value = nField.value.replace(/[^\d\,\.]/g, "").replace(/ /, "");
        }

    }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p>Currency Format using Javascript</p>
    <asp:TextBox runat="server" ID="TextBox4" onKeyPress="return MaskMoney1(event,2)" onkeyup="insertcommas(this)"></asp:TextBox>
   <asp:TextBox runat="server" ID="TextBox3" onKeyPress="return MaskMoney1(event,2)" onkeyup="insertcommas(this)"></asp:TextBox>
    <asp:TextBox runat="server" ID="TextBox2" onKeyPress="return MaskMoney1(event,2)" onkeyup="insertcommas(this)"></asp:TextBox>
    <asp:TextBox runat="server" ID="TextBox1" onKeyPress="return MaskMoney1(event,2)" onkeyup="insertcommas(this)"></asp:TextBox>
    </div>
   
    </form>
</body>
</html>

Happy Coding

Wednesday, 17 October 2012

Align Text in vertical using css

<html>
<head>
<title>
</title>
<style type="text/css" >
.Vertical
{
 
webkit-transform: rotate(-90deg);    
-moz-transform: rotate(-90deg);    
-o-transform: rotate(270deg);
writing-mode: tb-rl;
filter: fliph() flipv();    
font-weight:bold;    
font-family:Verdana;    
font-size:12px;

}
</style>
</head>
<body>
<table border="1" >
<tr>
<td class="Vertical">
English
</td>
<td class="Vertical">
Tamil
</td>
<td class="Vertical">
Maths
</td>
<td class="Vertical">
Science
</td>
<td class="Vertical">
social
</td>
</tr>
<tr>
<td >
95
</td>
<td >
85
</td>
<td >
64
</td>
<td >
88
</td>
<td >
76
</td>
</tr>
</table>
</body>
</html>

Tuesday, 16 October 2012

Text Area Validation for maximum length in java script and asp.net


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<head runat="server">
    <title></title>
    <script type="text/javascript">

        function TextAreaValidation(field, count, max)
        {
            if (field.value.length > max)
             {
                field.value = field.value.substring(0, max);
                field.blur();
                field.focus();
                return false;
            }
            else
            count.value = max - field.value.length;
           
        }
   </script>
  
</head>
<body>
    <form id="form1" runat="server">

<asp:TextBox runat="server" onblur="TextAreaValidation(this,this.form.counter,500);"
        onkeyup="TextAreaValidation(this,this.form.counter,500);"
        style="width: 352px; height: 74px" rows="5" cols="10" id="txtArea" TextMode="MultiLine" ></asp:TextBox>
<br />
Maximum Character<input type="text" onblur="TextAreaValidation(this.form.recipients,this,500);" disabled="disabled" onfocus="this.blur();"   value="500" name="counter" />
</form>
</body>
</html>

Sunday, 30 September 2012

Export Excel From DataTable using c#


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

namespace Export_Excel_With_Header_Color
{
    public partial class _Default : System.Web.UI.Page
    {
        MySqlConnection ObjCon = new MySqlConnection("server=localhost;user id=root;Password=admin;database=college");
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
           DataTable dt = new DataTable();
            MySqlDataAdapter ObjAda = new MySqlDataAdapter("Select * from rank",ObjCon);
            ObjAda.Fill(dt);
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.ClearHeaders();
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.ContentType = "application/ms-excel";
       
            HttpContext.Current.Response.Write(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">");
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=Reports.xls");

            HttpContext.Current.Response.Charset = "utf-8";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
            HttpContext.Current.Response.Write("<font style='font-size:20.0pt; font-family:Calibri;'>");
            HttpContext.Current.Response.Write("<BR><BR><BR>");
            HttpContext.Current.Response.Write("<Table border='1' bgColor='#ffffff' borderColor='#000000' cellSpacing='0' cellPadding='0' style='font-size:10.0pt; font-family:Calibri; background:white;'> <TR>");
            int columnscount = dt.Columns.Count;

            for (int j = 0; j < columnscount; j++)
            {
                HttpContext.Current.Response.Write("<Td style='background-color:Blue'>");
                HttpContext.Current.Response.Write("<B>");
                HttpContext.Current.Response.Write(dt.Columns[j].ColumnName.ToUpper());
                HttpContext.Current.Response.Write("</B>");
                HttpContext.Current.Response.Write("</Td>");
            }
            foreach (DataRow row in dt.Rows)
            {
                HttpContext.Current.Response.Write("<TR>");
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    HttpContext.Current.Response.Write("<Td style='width:150px'>");
                    HttpContext.Current.Response.Write(row[i].ToString());
                    HttpContext.Current.Response.Write("</Td>");
                }

                HttpContext.Current.Response.Write("</TR>");
            }
            HttpContext.Current.Response.Write("</Table>");
            HttpContext.Current.Response.Write("</font>");
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }

 
    }
}

Refresh parent window when child window is closed using javascript

Here is code for you for the demonstration i just put a date time on the parent window and when i close the child window ,the parent window get refresh and notice the time get changed.it will works on all browsers .HAPPY CODING!!!!