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