Tuesday, 30 April 2013

JQUERY TIPS

       
     
      As a follower of JQuery, I would like to share some of the Jquery tips which I use in day to day coding. Hope you find it useful.


      1.      To hide or show an element.

 $("#EmailTextBox").hide();
    $("#NameLabel").show();

      2.      To set an alternative background color of a HTML table.

 $("#Table tbody tr:even").css("background-color", "#F7F7F7");
     $("#Table tbody tr:odd").css("background-color", "#F0F0F0");


      3.      To disable or enable an element.

$("#DropDownList").attr("disabled", "disabled");
$("#DropDownList").removeAttr("disabled");


      4.      To check the SelectedIndex of a dropdownlist

var selectedIndex = $("DropDownList").prop("selectedIndex");
    if (selectedIndex == 1) {
        //Write code
    }

Tuesday, 5 June 2012

(ASP.NET) PreviousPage Property

The PreviousPage property can be used when we want to pass values between two aspx pages.
This property is useful when you do not want to use Server.Transfer to access value from previous page.
Consider an example, where we want to pass a label value from one page to another page.

Steps to do:
Main Page

  1. Place a label and a button control.
  2. Assign the label value to “Previous” and PostBackUrl of button control to Next page.
  3. In the code behind, create a property and return the label value.

Next Page

1.      Declare PreviousPageType directive in the aspx page.
2.      Place a label control in the Next Page.
3.      In the Page_Load, if the page is not postback, and if the previouspage is not null, then assign the property from previouspage to the label.


Main Page

.aspx

<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Value" runat="server" Text="Previous"></asp:Label>
        <asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="~/Next.aspx" />
    </div>
    </form>
</body>

.aspx.cs

public string Property
{
    get
    {
        return this.Value.Text;
    }
}


Next Page

.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Next.aspx.cs" Inherits="Next" %>
<%@ PreviousPageType VirtualPath="~/Main.aspx" %>

<!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>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>


.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            if (PreviousPage != null)
            {
                this.Label1.Text = (this.PreviousPage as Main).Property;
            }
        }
    }

Friday, 11 May 2012

(SQL SERVER) To find the row count of all tables in a database


Execute the below query to find the table names and the row count of the corresponding tables in a database.


SELECT
    sysobjects.Name
    , sysindexes.Rows
FROM
    sysobjects
    INNER JOIN sysindexes
    ON sysobjects.id = sysindexes.id
WHERE
    type = 'U'
    AND sysindexes.IndId < 2
ORDER BY
    sysobjects.name


The row count of a particular table can be found by executing
  
exec sp_spaceused 'tablename'