Saturday, December 10, 2011

Accordian headers all collapsed initially on page load

Accordion1.SelectedIndex = -1;
Accordion1.RequireOpenedPane = false;

Expand All / Collapse All panes in Ajax Accordion Extender


There is no direct way to Expand/Collapse all panes in Accordion Extender. Using following java script, Accordion can be Expand/Collapse all panes in one click.

<script type="text/javascript">
    function pageLoad()
    {
    collapseAll();
    }
    function collapseAll()
    {
        var behavior = $get("<%=UserAccordion.ClientID%>").AccordionBehavior;
            for (var i = 0; i < behavior._panes.length; i++) {
                behavior.get_Pane(i).content.style.display = 'none';
                behavior.get_Pane(i).content.height = 0;
                behavior.get_Pane(i).content.style.height = '0px';
            }           
            behavior.set_SelectedIndex(-1);
    }
    function expandall()
    {
       var behavior = $get("<%=UserAccordion.ClientID%>").AccordionBehavior;
            for (var i = 0; i < behavior._panes.length; i++) {
                behavior.get_Pane(i).content.style.display = 'block';
                behavior.get_Pane(i).content.height = behavior.get_Pane(i).content.scrollHeight;
                behavior.get_Pane(i).content.style.height = behavior.get_Pane(i).content.scrollHeight + 'px';
            }

    }
    </script>



Tuesday, October 18, 2011

Mathematical Functions in C#

Popular mathematical functions are summarized in the following table. Note that certain functions do not require the Math. prefix.

Function Use
Math.Abs() Returns the absolute value.

Math.Abs(-10) returns 10.

Math.Ceiling() Returns an integer that is greater than or equal to a number.

Math.Ceiling(5.333) returns 6.

Fix() Returns the integer portion of a number.

Fix(5.3333) returns 5.

Math.Floor() Returns an integer that is less than or equal to a number.

Fix(5.3333) returns 5.

Int() Returns the integer portion of a number.

Int(5.3333) returns 5.

Math.Max() Returns the larger of two numbers.

Math.Max(5,7) returns 7.

Math.Min() Returns the smaller of two numbers.

Math.Min(5,7) returns 5.

Math.Pow() Returns a number raised to a power.

Math.Pow(12,2) returns 144.

Rnd() Returns a random number between 0 and 1. Used in conjunction with Randomizestatement to initialize the random number generator.

Math.Round() Rounds a number to a specified number of decimal places. Rounds up on .5.

Math.Round(1.1234567,5) returns 1.12346.

Math.Sign() Returns the sign of a number. Returns -1 if negative and 1 if positive.

Math.Sign(-5) returns -1.

Math.Sqrt() Returns the square root of a positive number.

Math.Sqrt(144) returns 12.

Sunday, October 9, 2011

How to Convert DataReader to DataTable


string connString = ConfigurationManager.ConnectionStrings["NorthwindConn"].ConnectionString;
        SqlConnection conn = new SqlConnection(connString);
        string query = "SELECT * FROM Customers";
        SqlCommand cmd = new SqlCommand(query, conn);
        conn.Open();
        SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        DataTable dt = new DataTable();

        dt.Load(dr);

        conn.Close();

Wednesday, October 5, 2011

how to query sql server database size


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string strCount;
            SqlConnection Conn = new SqlConnection
               ("Data Source=W3INTECH-PC\\sqlexpress;Initial Catalog=aliintDatb;Integrated Security=True;");
            SqlCommand testCMD = new SqlCommand
               ("sp_spaceused", Conn);

            testCMD.CommandType = CommandType.StoredProcedure;

            Conn.Open();

            SqlDataReader reader = testCMD.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    Console.WriteLine("Name: " + reader["database_name"]);
                    Console.WriteLine("Size: " + reader["database_size"]);
                }
            }

            Console.ReadLine();
        }
    }
}

Ajax CalendarExtender displaying at wrong position in Chrome

< script type ="text/javascript" language ="javascript">     function onCalendarShown(sender, args)...