Sunday, October 9, 2011

What is difference between OR (|) and Logical OR (||) ?

1. Logical OR Sign is || and AND Sign is  |.
2. Both work is same but Operation Method is Different 
for example 
if(a==10 || b==10) 
here if a =10 then condition is Satisfied and not going checking values of B. 
Moral One Operation for checking second i.e B values decrasesand in AND & operation 
if(a==10 | b==10)
here if a ==10 then also it is checking B value i.e  it is not necessary.    
    
Logical OR(||) is Best.    

What is difference between AND & and Logical AND &&?

1. Logical AND Sign is && and AND Sign is  &.
2. Both work is same but Operation Method is Different
for example
if(a==10 && b==10)
here if a =10 then only it going for  checking b value
if a !=10 then condition is not satisfied.
Moral One Operation for checking second values decrases
and in AND & operation
if(a==10 & b==10)
here if a !=10 then also it is checking B value it is not necessary.
Logical AND(&&) is Best.    

Wednesday, October 5, 2011

Custom Validation On ServerSide For Validate Number in asp.net

Server Side Custom Validation  For Number. 
it is check regular expression for Number and must be not  null value means 
Required Field Validation.
 
 CustomValidation.aspx 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CustomValidation.aspx.cs"
    Inherits="CustomValidation" %>

<!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>CustomValidation ASPdotNet-Example.blogspot.com</title>
</head>
<body>
    <form id="form1" runat="server">
    <center>
    <h1>
        CustomValidation ASPdotNet-Example.blogspot.com</h1>
    <div>
        <table>
            <tr>
                <td>
                &nbsp;
                </td>
                <td>
  <asp:CustomValidator ID="CustomValidatorNumber" runat="server" ForeColor="Red" 
  ControlToValidate="txtValidation" ValidationGroup="Number"
  onservervalidate="CustomValidatorNumber_ServerValidate" 
                        ValidateEmptyText="True"></asp:CustomValidator>
                </td>
            </tr>
            <tr>
                <td>
  <asp:Label ID="lblNumber" runat="server"  Text="Number"></asp:Label>
                </td>
                <td>
 <asp:TextBox ID="txtValidation" ValidationGroup="Number" runat="server">
</asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                &nbsp;
                </td>
                <td>
  <asp:Button ID="btnSubmit" runat="server" Text="Submit" ValidationGroup="Number"
      onclick="btnSubmit_Click" />
                </td>
            </tr>
            <td>
                &nbsp;
                </td>
                <td>
         <asp:Label ID="lblMsg" runat="server" ForeColor="Green"></asp:Label>
                </td>
        </table>
    </div>
    </center>
    </form>
</body>
</html>
CustomValidation.aspx.cs

Sunday, October 2, 2011

gridview reorder row drag and drop

Drag and Drop GridView Row with jQuery.
Save Display Order in DataBase with WebMethod.
nodrag and nodrop for row that you are not want to drag and drop

gridview reorder row drag and drop




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

<!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">
    <script src="jquery-1.6.1.js" type="text/javascript"></script>
    <script src="jquery.tablednd_0_5.js" type="text/javascript"></script>
    <style>
        .noselect
        {
            -webkit-user-select: none;
            -khtml-user-select: none;
            -moz-user-select: none;
            -o-user-select: none;
            user-select: none;
            cursor: move;
        }
        .tDnD_whileDrag
        {
            background-color: Lime;
        }
    </style>
    <title>ASPdotNET-Example.blogspot.com</title>

<script type="text/javascript">
var strorder;
$(document).ready(function() {
$('#GridViewReorder').tableDnD(
{
    onDrop: function(table, row) {
    reorder();
    $.ajax({
             type: "POST",
             url: "GridViewReOrderDragandDrop.aspx/GridViewReorders",
             data: '{"Reorder":"'+strorder+'"}',
             contentType: "application/json; charset=utf-8",
             dataType: "json",
             async: true,
             cache: false,
             success: function (msg) {
             alert("Successfully Save ReOrder");
             }

           })
     }
}
);
});
function  reorder()
{ 
    strorder="";
    var totalid=$('#GridViewReorder tr td input').length;
    for(var i=0;i<totalid;i++)
    {
     strorder=strorder+$('#GridViewReorder tr td input')[i].getAttribute("value")+"|";
    }
}
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <center>
    <h1>GridView Reorder Drag And Drop</h1>
 <div>
 <asp:GridView ID="GridViewReorder" runat="server" HeaderStyle-CssClass="nodrag nodrop"
AutoGenerateColumns="False">
 <Columns>
    <asp:TemplateField ItemStyle-CssClass="noselect" HeaderText="ID">
      <ItemTemplate>
        <asp:Label ID="lblID" runat="server" Text='<%# Bind("id") %>'></asp:Label>
       <asp:HiddenField ID="hdnid" runat="server" Visible="true" Value='<%# Bind("id") %>' />
      </ItemTemplate>
     </asp:TemplateField>
        <asp:TemplateField ItemStyle-CssClass="noselect" HeaderText="Name">
       <ItemTemplate>
         <asp:Label ID="lblName" runat="server" Text='<%# Bind("name") %>'></asp:Label>
         </ItemTemplate>
        </asp:TemplateField>
     <asp:TemplateField HeaderText="Display Order" ItemStyle-CssClass="noselect">
        <ItemTemplate>
          <asp:Label ID="lblOrder" runat="server" Text='<%# Bind("displayorder") %>'>
</asp:Label>
          </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
</div>
    <h1> ASPdotNet-Example.blogspot.com</h1>
    </center>
    </form>
</body>
</html>
 


GridViewReOrderDragandDrop.aspx.cs

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Services;
public partial class GridViewReOrderDragandDrop : System.Web.UI.Page 
{
    SqlConnection strCon;
    string sql;
    SqlDataAdapter objAd;
    DataSet objDs;
    protected void Page_Load(object sender, EventArgs e)
    {
        GridViewReorder.DataSource = Con();
        GridViewReorder.DataBind();
    }
    protected DataSet Con()
    {
strCon = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
        objAd = new SqlDataAdapter("ListGrid", strCon);
        objDs = new DataSet();
        objAd.Fill(objDs);
        return objDs;
    }
    [WebMethod]

    public static void GridViewReorders(string Reorder)
    {
        string[] ListID = Reorder.Split('|');
        for (int i = 0; i < ListID.Length; i++)
        {
            if (ListID[i] != "" && ListID[i] !=null)
            {
                updateGridViewReorder(Convert.ToInt16(ListID[i]), i+1);
            }
        }

    }


    public static void updateGridViewReorder(int id, int DisplayOrder)
    {SqlConnection con ;
con= new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
        SqlCommand cmd = new SqlCommand("UpdateOrder");
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Connection = con;
        cmd.Parameters.AddWithValue("@id", id);
        cmd.Parameters.AddWithValue("@DisplayOrder",DisplayOrder);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    
    }
}

 Database Script

 
ASPdotNET-Example