Thursday, September 12, 2013

What is CSS and How to apply or use it in a HTML objects?


What is CSS?

CSS is knows as Cascading Style Sheet - This is an style sheet language used for describing the presentation of the document look and it is format and keep consistency all over the pages or documents. It is can be used any kind of language like HTML, XHTML, XML, SVG and XUL.

CSS is having all properties like color, width, height and many more html attributes.

Simple Example: CSS make web presentation more advanced.
Actually to define a style to a test in a div, We were used
<div><font color="Red" size="12">Testing Content </font></div>
if we need to use the same Red and 12px text again we have to write
<div><font color="Red" size="12">Testing Content </font></div>

But You can apply using CSS like this
Just define CSS Class by
<head>
<style>
.myfontStyle{font:#000 12px;}
</style>
</head>
<body>
<div class="myfontStyle">Testing - 1</div>
<div class="myfontStyle">Testing - 2</div>
</body>
Now let we see the ways to implement CSS in HTML. Actually, There are three ways to applying CSS to HTML

1. In-Line
2. Internal
3. External

1. In-Line

Directly, It is applied inside HTML tag using attribute called 'Style="<CSS Style Properties separated by Semi column(;) >"'

Example :
Directly write the property
<div style="font:#000 12px;height:15px;width:100px;">My test CSS inline</div>

2. Internal

Internal is more quicker and follow the consistency and easy apply to all objects to keep the same orientation.
This can be embeddeddefine as class and integrated through object ID.

Embedded:
<head>
<style>
div{font:#000 12px;}
</style>
</head>
<body>
<div>Testing - 1</div>
<div>Testing - 2</div>
</body>
Limitation: All DIV tags will automatically fixed as defined color and size. So it will be good at some cases. So be careful when it is handled. but there are more advanced way to over come it.Anyway, if you are basic user or learner to know before fix embedded method.

Define as CSS Class
<head>
<style>
.myfontStyle{font:#000 12px;}
</style>
</head>
<body>
<div class="myfontStyle">Testing - 1</div>
<div class="myfontStyle">Testing - 2</div>
</body>
Limitation: This class can be used inside a HTML page. If you want to use the same class in another document then you have to copy whole style and pasted again in <head> of the other page.
No more limitation :-) - Actually This is smarter way to design a object. Because you can call this class from any objects[if object accept the properties].

Using Object ID
<head>
<style>
#myfontStyle{font:#000 12px;}
#div2{font:#000 16px;}
</style>
</head>
<body>
<div id="myfontStyle">Testing - 1</div>
<div id="div2">Testing - 2</div>
</body>
Limitation: Some case, we can define style using #ID of the object. But HTML object has unique ID. So you can use this way, when you need unique design for particular object.


3. External

How you read and understand above explanation to define class internally in a document. External - will over come the limitation of internal.
Actually now you are going to write css class in file which will be created using extension (.css) <cssfilename>.css
This file will be referred/includes all HTML pages to drive same classes allover the HTML files.
Example:
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />

Useful Link:
To learn more about CSS properties : W3C School - CSS Properties Tutorial


Sunday, September 8, 2013

How to trigger Phone CALL / SMS / MMS from mobile website


This is very important now a days. Since smart phone and tablet users and usability are growing like a mushrooms. So it is good to give numbers along with clickable which directly ring screen/dial pad or send a text to using SMS or send image through MMS. Actually HTML 5 makes it so simple :-)

CALL TO NUMBER

Call when click image/icon
<a href="tel:5551234567"><img src="callme.jpg" /></a>
Or
It can be with text or directly number
<a href="tel:+15555555555">Call us free!</a>
<a href="tel:+15555555555">+1 555 55 55555</a>

Mordern devices support the scheme
<a href="tel:555-555-5555">555-555-5555</a>

SEND SMS

Every one like to sent Short Message Service [Known as SMS]
Mobile browsers usually invoke SMS compose window from a link when it is clicked.
This will be done through two possible URI Schemes [sms://] or [smsto://]

Actually to detect this sms:// and smsto:// protocol, Server is using Wireless Universal Resource File called as WURFL

Syntax:
sms://[<destination number or Leave empty, Compose window will get/prompt to select number(s) or recipient(s)>][?parameters]
OR
smsto://[<destination number or Leave empty, Compose window will get/prompt to select number(s) or recipient(s)>][?parameters]

<a href="sms://">Send SMS</a>
<a href="sms://?body=Visit http://w3rider.blogspot.in for more information">

Invite a friend by SMS<a>

<a href="sms://+919944393833">Contact us by SMS</a>
<a href="sms://+9944393833?body=To join our community https://www.facebook.com/w3rider">Join to our community</a>

Not very sure about browser compatibility which one of the above will work.

<a href="sms://">Send SMS</a>
<a href="sms://?body=Visit http://w3rider.blogspot.in for more information">Invite a friend by SMS<a>
<a href="sms://+919944393833">Contact us by SMS</a>
***BlackBerry : Actually for BlackBerry networks it has to be used like PIN:<number>

SEND MMS

Multimedia Messaging Service (MMS) - it send messages with multimedia content(Image, Video and any form for attachment). Actually it works by upload to the carrier and allow the receipient to download it from the carrier.

This will help to open multimedia message composor

mmsto://<destination number>

*** Symbian devices allow to send link directly by using
mms:<url>

Wednesday, April 18, 2012

ASP.Net 2.0 GridView Compute Column Sum using C#


To compute the GridView Sum in asp.net let’s take a simple example of SQL Database table. For GridView sum in ASP.net you can use the Northwind SQL database table to test the source code given in this tutorial. Here we will use products SQL table of Northwind database. In this tutorial we will compute the sum of units in stock of each product in the specified category.
Now you are ready to connect this SQL table with ASP.net web page to display the records in SQL table. But still you need a control to display the records in tabular format so that you could show the sum of column exactly below the Units in Stock column of GridView control.

ASP.Net 2.0 Gridview Sorting Using C#

ASP.Net 2.0 provides the sorting feature also in GridView Control. You can sort the records displayed using Gridview control in ascending or descending orderretrieved from sql database. You can use C# code to bind the SQL data with GridView control and follow the following simple steps to make your ASP.Net GridView control with sorting enabled. 
First of all drag the GridView control from Data controls menu. It will add the GridView control HTML source code as given above. Now click on GridView control to load the control properties at right side panel.
[code:html]
<asp:GridView id="GridView1" runat="server"></asp:GridView>
[/code]
To allow the sorting in GridView control select True from the dropdown list of AllowSorting property of Gridview as shown in above image.
This will add AllowSorting="True" in HTML source code of GridView Control.
Next step is to bind the Sorting event for GridView Control.
To bind the Sorting event of GridView control, double click on the Sorting event in the properties viewer of GridView. This will add the Sorting event in the HTML source code and C# code for Gridview.

HTML Source code for GridView Sorting

[code:html]<asp:GridView ID="GridView1"
              runat="server"
              CellPadding="2"
              AllowSorting="True" 
              OnSorting="GridView1_Sorting" 
              AutoGenerateColumns="False"
              Width="500px">
    <Columns>

        <asp:BoundField DataField="ProductID" HeaderText="ProductID" SortExpression="ProductName">
            <HeaderStyle HorizontalAlign="Left" />
        </asp:BoundField>

        <asp:BoundField DataField="ProductName" HeaderText="Product Name" SortExpression="ProductName">
            <HeaderStyle HorizontalAlign="Left" Width="200px" />
        </asp:BoundField>

        <asp:BoundField DataField="UnitsInStock" HeaderText="Units In Stock" SortExpression="UnitsInStock">
            <HeaderStyle HorizontalAlign="Left" />
            <ItemStyle HorizontalAlign="Center" />
        </asp:BoundField>

        <asp:BoundField DataField="UnitPrice" HeaderText="Price Per Unit" SortExpression="UnitPrice">
            <HeaderStyle HorizontalAlign="Left" />
            <ItemStyle HorizontalAlign="Center" />
        </asp:BoundField>

    </Columns>
</asp:GridView>
[/code]

C# Code for GridView Sorting

[code:c#]    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["sortOrder"] = "";
            bindGridView("","");
        }
    }

    public void bindGridView(string sortExp,string sortDir)
    {
        // string variable to store the connection string
        // defined in ConnectionStrings section of web.config file.
        string connStr = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;

        // object created for SqlConnection Class.
        SqlConnection mySQLconnection = new SqlConnection(connStr);

        // if condition that can be used to check the sql connection
        // whether it is already open or not.
        if (mySQLconnection.State == ConnectionState.Closed)
        {
            mySQLconnection.Open();
        }

        SqlCommand mySqlCommand = new SqlCommand("select top 10 ProductID, ProductName, UnitsInStock, UnitPrice from products", mySQLconnection);
        SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlCommand);
        DataSet myDataSet = new DataSet();
        mySqlAdapter.Fill(myDataSet);

        DataView myDataView = new DataView();
        myDataView = myDataSet.Tables[0].DefaultView;

        if (sortExp!=string.Empty)
        {
            myDataView.Sort = string.Format("{0} {1}", sortExp, sortDir);
        }

        GridView1.DataSource = myDataView;
        GridView1.DataBind();

        // if condition that can be used to check the sql connection
        // if it is open then close it.
        if (mySQLconnection.State == ConnectionState.Open)
        {
            mySQLconnection.Close();
        }

    }

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
     
        bindGridView(e.SortExpression, sortOrder);
       
    }

    public string sortOrder
    {
        get
        {
            if (ViewState["sortOrder"].ToString() == "desc")
            {
                ViewState["sortOrder"] = "asc";
            }
            else
            {
                ViewState["sortOrder"] = "desc";
            }

            return ViewState["sortOrder"].ToString();
        }
        set
        {
            ViewState["sortOrder"] = value;
        }
    }
[/code]

ASP.Net 2.0 Gridview Paging using C#


In ASP.Net 2.0 GridView is most often used to display the data retrieved from the database in Tabular form with features of Gridview like data pagingsorting andauto formats.
You can use C# code to bind the SQL data with GridView control and follow the following simple steps to make your ASP.Net GridView control with paging enabled.


First of all drag the GridView control from Data controls menu. It will add the GridView control HTML source code as given above. Now click on GridView control to load the control properties at right side panel.
[code:html]
<asp:GridView id="GridView1" runat="server"></asp:GridView>
[/code]
To enable the paging in GridView control select True from the dropdown list of AllowPaging property of GridView control as shown in the above image.
It will add AllowPaging="True" in HTML source code of Gridview.
Next step is to bind the data with Gridview control and handle the GridView paging event.
To bind the PageIndexChanging of GridView control, double click on thePageIndexChanging event in the properties of Gridview. It will add the event in HTML source code as well as C# code.

HTML source code for GridView Control

[code:html]
<asp:GridView ID="GridView1"
              runat="server"
              CellPadding="2"
              AllowPaging="True" 
              PageSize="10"
              OnPageIndexChanging="GridView1_PageIndexChanging" 
              AutoGenerateColumns="False"
              Width="500px">
    <Columns>

        <asp:BoundField DataField="ProductID" HeaderText="ProductID">
            <HeaderStyle HorizontalAlign="Left" />
        </asp:BoundField>

        <asp:BoundField DataField="ProductName" HeaderText="Product Name">
            <HeaderStyle HorizontalAlign="Left" Width="200px" />
        </asp:BoundField>

        <asp:BoundField DataField="UnitsInStock" HeaderText="Units In Stock">
            <HeaderStyle HorizontalAlign="Left" />
            <ItemStyle HorizontalAlign="Center" />
        </asp:BoundField>

        <asp:BoundField DataField="UnitPrice" HeaderText="Price Per Unit">
            <HeaderStyle HorizontalAlign="Left" />
            <ItemStyle HorizontalAlign="Center" />
        </asp:BoundField>

    </Columns>

</asp:GridView>
[/code]
You can set the PageSize value as per your requirement. 

C# Code Sample

[code:c#]
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            bindGridView();
    }

    public void bindGridView()
    {
        // string variable to store the connection string
         // defined in ConnectionStrings section of web.config file.
        string connStr = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;

        // object created for SqlConnection Class.
        SqlConnection mySQLconnection = new SqlConnection(connStr);

        // if condition that can be used to check the sql connection
        // whether it is already open or not.
        if (mySQLconnection.State == ConnectionState.Closed)
        {
            mySQLconnection.Open();
        }

        SqlCommand mySqlCommand = new SqlCommand("select ProductID, ProductName, UnitsInStock, UnitPrice from products", mySQLconnection);
        SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlCommand);
        DataSet myDataSet = new DataSet();
        mySqlAdapter.Fill(myDataSet);

        GridView1.DataSource = myDataSet;
        GridView1.DataBind();


        // if condition that can be used to check the sql connection
        // if it is open then close it.
        if (mySQLconnection.State == ConnectionState.Open)
        {
            mySQLconnection.Close();
        }
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        bindGridView();
    }
[/code]
After data binding with GridView control you will get the results as shown in the live sample of Gridview control on page load.