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>