Sunday 2 December 2012

Freeze column in html table

<html>
<head>
    <title></title>
    <style>
        table
        {
            font-family: verdana;
        }
        div#AdjResultsDiv
        {
            width: 200px;
            height: 200px;
            overflow-x: scroll;
            position: relative;
            font-family: verdana;
        }
        div#AdjResultsDiv th
        {
            background-color: navy;
            font-family: verdana;
            color: white;
            position: relative;
            cursor: default;
            top: expression(document.getElementById("AdjResultsDiv").scrollTop-2); /*IE5+ only*/
            z-index: 10;
        }
        td.locked, th.locked
        {
            font-family: verdana;
            color: white;
            background-color: navy;
            position: relative;
            cursor: default;
            left: expression(document.getElementById("AdjResultsDiv").scrollLeft-2); /*IE5+ only*/
        }
        div#AdjResultsDiv th.locked, div#AdjResultsDiv td.normal
        {
            z-index: 99;
        }
    </style>
</head>
<body>
    <div id="AdjResultsDiv">
        <table border="1" style="left: 1px; top: 155px; height: 1px;" cellpadding="0px" cellspacing="0px"
            align="center">
            <tr>
                <td class="locked" style="font-weight: bold; font-size: 12px; background-color: #69a6d0;
                    font-size: 12px; color: #ffffff; height: 19px; color: White;" width="100px" align="center">
                    Colunm1
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm2
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="250px" align="center">
                    Colunm3
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm4
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm5
                </td>
            </tr>
            <tr>
                <td class="locked" style="font-weight: bold; font-size: 12px; background-color: #69a6d0;
                    font-size: 12px; color: #ffffff; height: 19px; color: White;" width="100px" align="center">
                    Colunm1
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm2
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="250px" align="center">
                    Colunm3
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm4
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm5
                </td>
            </tr>
            <tr>
                <td class="locked" style="font-weight: bold; font-size: 12px; background-color: #69a6d0;
                    font-size: 12px; color: #ffffff; height: 19px; color: White;" width="100px" align="center">
                    Colunm1
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm2
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="250px" align="center">
                    Colunm3
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm4
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm5
                </td>
            </tr>
            <tr>
                <td class="locked" style="font-weight: bold; font-size: 12px; background-color: #69a6d0;
                    font-size: 12px; color: #ffffff; height: 19px; color: White;" width="100px" align="center">
                    Colunm1
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm2
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="250px" align="center">
                    Colunm3
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm4
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm5
                </td>
            </tr>
            <tr>
                <td class="locked" style="font-weight: bold; font-size: 12px; background-color: #69a6d0;
                    font-size: 12px; color: #ffffff; height: 19px; color: White;" width="100px" align="center">
                    Colunm1
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm2
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="250px" align="center">
                    Colunm3
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm4
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm5
                </td>
            </tr>
            <tr>
                <td class="locked" style="font-weight: bold; font-size: 12px; background-color: #69a6d0;
                    font-size: 12px; color: #ffffff; height: 19px; color: White;" width="100px" align="center">
                    Colunm1
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm2
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="250px" align="center">
                    Colunm3
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm4
                </td>
                <td style="font-weight: bold; font-size: 12px; color: #ffffff; height: 19px; background-color: #69a6d0;
                    color: White;" width="100px" align="center">
                    Colunm5
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

write error message in Notepad using C#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net.Mail;
using System.Net;

public partial class ErrorMessageInNotePad : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnCreateError_Click(object sender, EventArgs e)
    {
        try
        {
            throw new System.ArgumentException("Sajil Created the ErrorMessage!!!");
        }
        catch (Exception ex)
        {
//HERE YOU CAN USE PAGE NAME,FILE NAME,MODULE NAME OR FUNCTION                                               NAME TO   IDENTIFY THE ERROR SPOT  AND YOU CAN ALSO MAKE THESE CODE AS SAPARATE FUNCTION  AND USE IN CACTH BLOCK.

            StreamWriter sw = new StreamWriter(Server.MapPath("ErrorNotepad") + "\\ErrorList.txt", true);
            sw.WriteLine("Error occurred at", DateTime.Now.ToString());
            sw.WriteLine(ex.Message, DateTime.Now.ToString());
            sw.Dispose();
//CODE FOR SEND MAIL THAT NOTEPAD
            MailMessage newmsg;
            MailAddress mailfrom = new MailAddress("xxxxx.com");
            MailAddress mailto = new MailAddress("xxxxx.com");
            newmsg = new MailMessage(mailfrom, mailto);

            newmsg.Body ="You Have Error Message!!!";
         
            Attachment att = new Attachment(Server.MapPath("ErrorNotepad") + "\\ErrorList.txt");

            newmsg.Attachments.Add(att);
            SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new NetworkCredential("xxxxx", "xxxxx");
            smtp.EnableSsl = true;
            smtp.Send(newmsg);
           

        }
    }
}
POST COMMENT IF ITS USEFULL,HAPPY CODING.....

Wednesday 28 November 2012

how to get previous page value in asp.net

In First Page
--------------
   protected void btn_Click(object sender, EventArgs e)
    {
           //hnd is the hidden field
            hdn.Value = "sajil";
            Server.Transfer("SecondPage.aspx", true);
     }
In second Page
--------------
 You can get this hdn value in the second page using the code below

   protected void Page_Load(object sender, EventArgs e)
  {
    HiddenField txt = (HiddenField)Page.PreviousPage.FindControl("hdn");
    Response.Write(txt.Value);
  }

Saturday 24 November 2012

printing problem

getting paper wasted in top 

ref:secont picture paper get wasted like this

Monday 19 November 2012

Highlight Gridview Row When CheckBox is Checked using javascript


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

<!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 CheckClick(obj) {
            //Get the Row based on checkbox order
            var row = obj.parentNode.parentNode;
            if (obj.checked) {
                //If checked change color to Red
                row.style.backgroundColor = "Red";
            }
               else {
                row.style.backgroundColor = "white";
            }
           //Get the reference of GridView
            var GridView = row.parentNode;

            //Get all input elements in Gridview
            var inputList = GridView.getElementsByTagName("input");

            for (var i = 0; i < inputList.length; i++) {
                //The First element is the Header Checkbox
                var headerCheckBox = inputList[0];

                //Based on all or none checkboxes
                //are checked check/uncheck Header Checkbox
                var checked = true;
                if (inputList[i].type == "checkbox" && inputList[i] != headerCheckBox) {
                    if (!inputList[i].checked) {
                        checked = false;
                        break;
                    }
                }
            }
            headerCheckBox.checked = checked;

        }
        function checkAll(objRef) {
            var GridView = objRef.parentNode.parentNode.parentNode;
            var inputList = GridView.getElementsByTagName("input");
            for (var i = 0; i < inputList.length; i++) {
                //Get the Cell To find out ColumnIndex
                var row = inputList[i].parentNode.parentNode;
                if (inputList[i].type == "checkbox" && objRef != inputList[i]) {
                    if (objRef.checked) {
                        row.style.backgroundColor = "Red";
                        inputList[i].checked = true;
                    }
                    else {
                        row.style.backgroundColor = "white";
                        inputList[i].checked = false;
                    }
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="sm" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel runat="server" ID="up">
            <ContentTemplate>
                <div>
                    <asp:GridView ID="gvBank" runat="server">
                        <HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
                        <Columns>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    <asp:CheckBox ID="chkHeader" runat="server" onclick="checkAll(this);" />
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:CheckBox ID="chkChild" runat="server" onclick="CheckClick(this)" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </div>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>


Highlight Gridview Row When CheckBox is Checked in Asp.Net and C#

In this article I will explain how to highlight gridview rows when checkbox is checked or selected in asp.net using C#
ASPX page:

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

<!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>

   </head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="sm" runat="server" ></asp:ScriptManager>
    <asp:UpdatePanel runat="server" ID="up">
    <ContentTemplate>
    <div>
        <asp:GridView ID="gvBank" runat="server">
            <HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
            <Columns>
                <asp:TemplateField>
                    <HeaderTemplate>
                        <asp:CheckBox ID="chkHeader" runat="server"
                            oncheckedchanged="chkHeader_CheckedChanged"  AutoPostBack="true"/>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="chkChild" runat="server"
                            oncheckedchanged="chkChild_CheckedChanged" AutoPostBack="true" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    </div>
      </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>
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.Configuration;
using System.Data;

public partial class GridviewCheckBox : System.Web.UI.Page
{
    MySqlConnection con = new MySqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
    MySqlCommand cmd = new MySqlCommand();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataSet ds = new DataSet();
            MySqlDataAdapter ada = new MySqlDataAdapter("SELECT Bank_Nam,STR_TO_DATE(cre_dt,'%m/%d/%Y %T') as CreatedDate,STR_TO_DATE(Mod_dt,'%m/%d/%Y %T') as ModifiedDate,Cre_by,Mod_by FROM bank  order by Bank_Nam", con);
            ada.Fill(ds);

            gvBank.DataSource = ds.Tables[0];
            gvBank.DataBind();
        }

    }
    protected void chkChild_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox checkbox = (CheckBox)sender;

        GridViewRow gdrow = (GridViewRow)checkbox.NamingContainer;
        if (((CheckBox)gdrow.FindControl("chkChild")).Checked)
            gdrow.BackColor = System.Drawing.Color.Red;
        else
            gdrow.BackColor = System.Drawing.Color.Transparent;

    }
    protected void chkHeader_CheckedChanged(object sender, EventArgs e)
    {
        foreach (GridViewRow rw in gvBank.Rows)
        {
            CheckBox chkBx = (CheckBox)rw.FindControl("chkChild");
            if (chkBx != null && chkBx.Checked)
                gvBank.BackColor = System.Drawing.Color.Transparent;
            else
                gvBank.BackColor = System.Drawing.Color.Gold;
        }


        
    }
}

Sunday 11 November 2012

Show tooltip in Asp.net Dropdownlist items Mouse over Event in C#

Here I going to explain how to show tooltip in dropdownlist items on mouseover event in asp.nt using C#
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.Configuration;
using System.Data;

public partial class ToolTip_in_DropDown_ListItem : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString());
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Binddropdown();
        }
    }
    protected void Binddropdown()
    {

        con.Open();
        SqlCommand cmd = new SqlCommand("select EmpNam from Employee", con);
        cmd.ExecuteNonQuery();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        ddl.DataSource = ds;
        ddl.DataTextField = "EmpNam";
        ddl.DataValueField = "EmpNam";
        ddl.DataBind();
    }
    protected void ddl_DataBound(object sender, EventArgs e)
    {
        DropDownList ddl = sender as DropDownList;
        if(ddl.Text!=null)
        {
            foreach (ListItem listItem in ddl.Items)
              {
                   listItem.Attributes["title"] = listItem.Text;
                  //or you can use this
                  //   item.Attributes.Add("Title", listItem.Text);
             } 
        }

    }
}

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

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <center>
     <asp:DropDownList runat="server" ID="ddl" ondatabound="ddl_DataBound" ></asp:DropDownList>
    </center>
   
    </div>
    </form>
</body>
</html>





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!!!!