Monday 25 February 2013

Validation at least one before and one after decimal



  <asp:TextBox ID="txttotalarea" runat="server"
                                                    Width="90px" onKeyUp="fillareaandunit(this.id);">0</asp:TextBox>



 function fillareaandunit(id) {
            var e = document.getElementById("" + id + "");
            var regexp = ^\d{0,M}\.?\d{0,N}$;
            if (!regexp.test(e.value)) {
                alert("Please enter onyl number.");
                e.value = e.value.substring(0, e.value.length - 1);
                return false;
            }


M = at most number of digits before decimal point
N = at most number of digits after decimal point

decimal number with two digit precision


 function fillareaandunit(id) {
            var e = document.getElementById("" + id + "");
            var regexp =^\d*\.?\d{0,2}$;
            if (!regexp.test(e.value)) {
                alert("Please enter onyl number.");
                e.value = e.value.substring(0, e.value.length - 1);
                return false;
            }

number only validataion



function fillareaandunit(id) {
            var e = document.getElementById("" + id + "");
            var regexp = /^[0-9]+$/;
            if (!regexp.test(e.value)) {
                alert("Please enter onyl number.");
                e.value = e.value.substring(0, e.value.length - 1);
                return false;
            }




<asp:TextBox ID="txttotalarea" runat="server"
                                                    Width="90px" onKeyUp="fillareaandunit(this.id);">0</asp:TextBox>

Numeric and decimal only validation in textbox


function fillareaandunit(id) {
            var e = document.getElementById("" + id + "");
            var regexp = /^\d*\.?\d*$/;
            if (!regexp.test(e.value)) {
                alert("Please enter onyl number.");
                e.value = e.value.substring(0, e.value.length - 1);
                return false;
            }


<asp:TextBox ID="txttotalarea" runat="server"
                                                    Width="90px" onKeyUp="fillareaandunit(this.id);">0</asp:TextBox>

Thursday 21 February 2013

delete duplicate record from table



WITH tablealias (id, DuplicateCount)
AS
(
SELECT id,ROW_NUMBER() OVER(PARTITION BY id ORDER BY id) AS DuplicateCount FROM emp
)
DELETE FROM tablealias WHERE DuplicateCount > 1
go

//with sub query
select * from (
SELECT id,ROW_NUMBER() OVER(PARTITION BY id ORDER BY id) AS DuplicateCount FROM emp
)tt where DuplicateCount>1

// we can take more than one fields with table

Thursday 14 February 2013

gridview export in excel

string datestyle = @"<style> .nf{mso-number-format:\@;}</style>";
        MainGridView.Visible = true;
        MainGridView.ForeColor = System.Drawing.Color.Black;
        MainGridView.AllowPaging = false;
         MainGridView.DataSource = Session["objListRechargeDTO"];
         MainGridView.DataBind();
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=OneCardTransactionReport.xls");
        Response.Charset = "";
        Response.ContentType = "application/xls";
        System.IO.StringWriter WriteItem = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlText = new HtmlTextWriter(WriteItem);
        MainGridView.HeaderRow.Style.Add("background-color", "#CCCCCC");
        MainGridView.HeaderRow.Style.Add("background-color", "#CCCCCC");
       // MainGridView.Columns[2].Style.Add("Color","#000000");
        MainGridView.Columns[0].Visible = false;
        MainGridView.Columns[13].Visible = false;
        MainGridView.Columns[14].Visible = false;
        for (int i = 0; i < MainGridView.Rows.Count; i++)
        {
            HyperLink hl = (HyperLink)MainGridView.Rows[i].FindControl("hl");
            hl.NavigateUrl = "";
            HyperLink custemail = (HyperLink)MainGridView.Rows[i].FindControl("custemail");
            custemail.NavigateUrl = "";
        }
            Response.Write(datestyle);
        MainGridView.AllowPaging = false;
        MainGridView.RenderControl(htmlText);
        Response.Write(WriteItem.ToString());
        // Response.BinaryWrite((byte[])command.ExecuteScalar());
        Response.End();

Get anchar tag on server side in asp.net

html//
<a id="cust_act" class="tools-text" title="Validate Customer" href='............' onserverclick="Cust_Validate" onclick="return confirm('Are you sure to do this Record?')" runat="server">
   your text</a>

onserver side

protected void Cust_Validate(object s, System.EventArgs e)
    {
        HtmlAnchor cust_act = (HtmlAnchor)s;
        string ID = cust_act.HRef;
string ID = cust_act.InnerText;
}

string replace all space and new line

//space with line 
string mm=  Regex.Replace(yourSting, @"\s", "");


//new line
            string ttt = Regex.Replace(yourSting, @"\t|\n|\r", "");

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...