Thursday, 8 December 2011

How to Add day to a particular date and how to set Date format of a particular Date


TxtDate.Text = Now.Date.ToString("dd/MM/yyyy")
LblD1.Text = " " & Now.Date.AddDays(1).Day
LblD1.ToolTip = Now.Date.AddDays(1).Date.ToString("dd/MM/yyyy")
       

Time Sorting if AM and PM Charaters are Exist


select data,data_id from master_data where master_id = 9 and active = 1
orderby(substring(data,charindex('',data)+1,len(data))),data

Output :

07-12 AM     
09-10 AM     
01-03 PM     
03-05 PM    
05-07 PM    

How to make a Event Function of Drop Down List which is Inside the GridView.

Some time a user faced the Problem that how to make event function of Drop Down list and TextBox Events function which are inside the Gridview. And how the Drop Down list Control Finds the Row index. For this Solution It can be done by given blow Function.


Protected Sub DdlWeight_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim master As DropDownList = sender
        Dim DdlWeigh1 As String
        Dim oldAmount As Double
        Dim diff As Double
        Dim qty1 As String
        Dim GdvPrice As GridViewRow = master.Parent.Parent

'the Given below Lines Important to find Control in 'a same rowindex. It will Automatically run even 'function of same row index in which Drop Down list 'exist not another row Control. As Given Below:


        Dim Price As Label = GdvPrice.FindControl("ProdPrice")

        Dim QTY As TextBox = GdvPrice.FindControl("txtqty")

        Dim DdlWeight As DropDownList = GdvPrice.FindControl("DdlWeight")

        Dim Amount As Label = GdvPrice.FindControl("lblAmount")

        oldAmount = Val(Amount.Text)
        If DdlWeight.SelectedValue <> 0 Then
            qty1 = QTY.Text
            DdlWeigh1 = DdlWeight.SelectedItem.Text

            Dim GmKG As Array
            GmKG = Split(DdlWeigh1, " ")
            If GmKG(1) = "GM" Then
                Amount.Text = ((Val(Price.Text) / 1000) * (Val(GmKG(0)) * Val(qty1))).ToString()
            ElseIf GmKG(1) = "KG" Then
                Amount.Text = (Val(Price.Text) * (Val(GmKG(0)) * Val(qty1))).ToString()
            End If

            If oldAmount < Convert.ToDouble(Amount.Text) Then
                diff = Convert.ToDouble(Amount.Text) - oldAmount
                LblTotalAmt.Text = (diff + Convert.ToDouble(Val(LblTotalAmt.Text))).ToString()
            Else
                diff = oldAmount - Convert.ToDouble(Amount.Text)
                LblTotalAmt.Text = (Convert.ToDouble(LblTotalAmt.Text) - diff).ToString()
            End If

        Else
            Amount.Text = "0"
            diff = oldAmount - Convert.ToDouble(Amount.Text)
            LblTotalAmt.Text = (Convert.ToDouble(LblTotalAmt.Text) - diff).ToString()

        End If
        CalExtraChages(Val(LblTotalAmt.Text))
        TotalKiloGrams()
    End Sub



Monday, 28 November 2011

How to Create table as Same as another Database table using query


Syntax:-
Select * into <New Table> from <Database.Dbo.Table>

Example:-
select * into Menu_master from accord.dbo.Menu_master

Q. What is the Difference between Delete and Truncate Command

Q. What is the Difference between Delete and Truncate Command

   Delete                                Truncate

1) Delete Record do not              1) The record will       save until they                        be remove permanently
are committed and they                 by the truncate command
can be Roll backed.        
         
2) Delete Command effects in          2) Truncate command do
   Triggers.                             not effect Triggers

3) It Process is slow                 3) Process fast as 
                                         compare to Delete

Saturday, 26 November 2011

How to Validate server side controls in Asp.net using Custom Validator


Some times we require that the page should not be submitted when server side control is being used.

We have two kinds of server side control validation as given below:
1). TextBox Custom Validation
2). File Upload control custom Validation


1). TextBox Custom Validation

Java Script :

function ConfirmApproval(source, args)
    {
   
  //debugger;
        var t1 = document.getElementById("TxtCurrDate").value;
        var t2 = args.Value//document.getElementById("TxtHidden").value;
        if(args.Value == t1)
            {
//            alert('hello');
//            }
                var r=confirm("The Price on this Date are already in Database, Do Your Really wants to Update !");
                if (r==true)
                  {
                        args.IsValid = true;
                        return;
//                      return true;
                  }
                else
                  {    
                        args.IsValid = false;
                        return;
//                        return false;
                  }       
        }   

    }



Custom Validator control Validation:

<asp:CustomValidator id="CheckUpdate"
        runat="server"
        ControlToValidate="TxtHidden"
        ValidateEmptyText="true"
        ClientValidationFunction="ConfirmApproval"
        Display="None">custom validator</asp:CustomValidator><br />



2). File Upload control custom Validation


Java Script :

function ValidateUpl(source, args)
    {  
        //debugger;
        var fuData = document.getElementById('<%= UplFile.ClientID %>');
        var FileUploadPath = fuData.value;

            if(FileUploadPath =='')
                {
                 alert('Please choose Excel file for update Rate list.');
                 args.IsValid = false;
                }
                 else
                {
                 var Extension = FileUploadPath.substring(FileUploadPath.lastIndexOf('.') + 1).toLowerCase();

                if (Extension == "xls")
                {
                args.IsValid = true; // Valid file type
                 }
                else
                {
                alert('Please choose Excel file for Update Rate list.');
                args.IsValid = false; // Not valid file type
                }
                }

    }


Custom Validator control Validation:

<asp:CustomValidator ID="CustomValidator1"
        runat="server"
        ClientValidationFunction="ValidateUpl"
        ControlToValidate="UplFile"
        ErrorMessage="CustomValidator" Display ="None"
        ValidateEmptyText="True"></asp:CustomValidator

Friday, 18 November 2011

How to set Short Cut key in Asp.net Application Using Java Script


//This line is very Importance
 
document.onkeydown = checkKeycode

function checkKeycode(e)
{
var keycode;
if (window.event)
keycode = window.event.keyCode;
else
    if (e.which == 113) // for F2 Key of Key board
    //keycode = e.which;
    //alert("keycode: " + keycode);
    document.getElementById("ImgBtnRoute").click();


}