Sunday, 28 April 2013

Extensible Markup language (XML).

         XML Stands for Extensible Markup Language. Its a language much like HTML which was designed to carry data, not to display data and also self-descriptive. XML does not do anything. XML was created to structure,store and transport information. XML tags are not predefined, you must define your own tags. XML is not a replacement for HTML, HTML and XML were designed with different goals:
  • XML was designed to transport and store data, with focus on what data is.
  • HTML was designed to display data, with focus on how data looks.
  • HTML is about displaying information, while XML is about carrying information.
To create an XML document we need to satisfy a set of rules that are prescribed by W3C, as following
  • An XML doc has to be saved with .xml extention.
  • Data under XML doc should be present only under tags, where every tag should have a start and end element.       eg:   <Tag><Tag> Or <Tag id="1"/>
  • Tags can also be defined with attribute which are user-defined where value to attribute should be enclosed under double quotes.
  • While defining tags start and end tag should match in case.
  • An Xml doc can only have one root element.

Friday, 26 April 2013

Accessing MS Excel data from .Net Application

Ms Excel is a file system which stores data in the form of rows and columns same as a database table. An Excel document is referred as Work Book that contains Work Sheets in it, work books are considered as databases and work sheets are considered as tables.First row of work sheet can store column names.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;

namespace WinForms7
{
    public partial class Form6 : Form
    {
        public Form6()
        {
            InitializeComponent();
        }
        OdbcConnection con; OdbcCommand cmd; OdbcDataReader dr; string Sqlstr;
        private void Form6_Load(object sender, EventArgs e)
        {
            con = new OdbcConnection("Dsn=ExcelDsn; ReadOnly=0");
            cmd = new OdbcCommand();
            cmd.Connection = con;
            con.Open();
            LoadData();
            label1.Text = dr.GetName(0); label2.Text = dr.GetName(1);
            label3.Text = dr.GetName(2); label4.Text = dr.GetName(3);
               
        }
        private void LoadData()
        {
            cmd.CommandText = "Select * from[Student$]";
            cmd.ExecuteReader();
            ShowData();


        }
        private void ShowData()
        {
            if (dr.Read())
            {
                textBox1.Text = dr[0].ToString();
                textBox2.Text = dr[1].ToString();
                textBox3.Text = dr[2].ToString();
                textBox4.Text = dr[3].ToString();
            }
            else
                MessageBox.Show("No data exists");

               
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ShowData();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox2.Text = textBox3.Text = textBox4.Text = " ";
            textBox1.Focus();
        }
        private void ExecuteDML()
        {
            dr.Close();
            cmd.CommandText = Sqlstr;
            if (cmd.ExecuteNonQuery() > 0)
                MessageBox.Show("Insert or Update operation was successful");
            else
                MessageBox.Show("Insert or Update operation failed");

                LoadData();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Sqlstr = String.Format("Insert into [Stident$] values({0},'{1}' {2},{3})", textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text);
            dr.Close();
            ExecuteDML();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Sqlstr = String.Format("Update [Stident$] Set Sname='{0},Class={1}, Fees= {2} where Sno={3}", textBox2.Text, textBox2.Text, textBox3.Text, textBox4.Text);
            dr.Close();
            ExecuteDML();
        }
    }
}

Thursday, 25 April 2013

DataList, Repeater and FormView and Details View Controls

Today, I practiced some examples using Data List Control, Repeater and FormView Controls in Asp.Net.
 
DataList Control: 

Datalist control is similar to gridview except that it has no predefined layout and hence it can be designed in any layput you want, which is not possible with gridview because it has predefined table layout. It doesn't support paging and sorting wheareas gridview supports paging and sorting.

Repeater:

Repeater control can display multiple rows to gridiew and datalist. But unlike gridview and datalist the data in repeater is readonly.Similar to datalist it has no predefined layout and you can design it with any layout. As repeater is readonly, it has very limited set of properties, methods and events and hence it is very light weight and provides fast access, it has the important properties DatasourceId and Datasource. It has only one important event ItemCommand that will be raised when user click on any button within the repeater.

Wednesday, 24 April 2013

GridVeiw

GridVeiw control is one of the data controls provided in ASP.net that can display Multiple rows at a time. GridVeiwhas a predefined table layout that displays the data in the table format. Gridveiw supports update, delete and sorting but it does not suppoort insert. Gridveiw also supports paging using which we can divide rows of the grid veiw into pages.

Properties
  • AllowPaging
  • PagerSettings
  • PageSize
  • PageIndex
  • AllowSorting
  • EnableSortingAndPagingCallbacks
  • AytoGenerateColumns
  • AutoGenerateDeleteButton
  • AutoGenerateEditButton
  • AutoGenerateSelectButton
  • Columns
  • DataKeyName
  • SelectedIndex
  • SelectedValue
  • DataSource
  • DataSourceID
  • EditIndex
  • EmptyDataText
  • HeaderRow
  • FooterRow
  • Rows
  • ShowHeader
  • ShoeFooter
Events
  • SelectedIndexChanging
  •  PageIndexChanging
  • RowEditing
  • RowUpdating
  • RowCancelingEdit
  • RowDeleting
  • Sorting

Tuesday, 23 April 2013

Image Map

Image Map is used to divide the image into different hotspots and allow the user to navigate to different pages by clicking on different hotspot or execute different code when user clicks on different hotspot or execute different code when user clicks on different hotspot based on the hotspot on which user clicked. It has thee property image URL to specify the image to display within the ImageMap and the property hotspots to specify different hotspots required within the image map.

Three different types of hotspots you can create within the Imagemap and they are circle hotspot, rectangle hotspot and polygon hotspot. The rectangle hotspot has the properties bottom,left, right and top to specify position and size of the rectangle hotspot and circle hotspot has the properties radius x and y to specify the radius and center point of the circle and polygon hotspot and circle hotspot has the property co ordinates to specify the points using which you want to draw the polygon.

All the types of hotspots have the following three properties :-
  • Hotspot Mode:-  Used to specify the mode of hotspot and it has the options like not set, inactive, navigate and postback.
  • Navigate Url:- Used to specify Url of the page to navigate when hotspot mode is set to navigate and user click on the hotspot.
  • Target :- When Hotspot Mode is set to navigate then this property is used to specify the target when to display the navigate URL.
 

Monday, 22 April 2013

Ad Rotator Control

Ad Rotator is used to display advertisements on the page and change the advertisement with every request. Ad rotator support displaying the advertisement from an XML file and also from the database.

Properties:
  • Advertisement File: When you want to display advertisements in the ad rotator from a XML file then this property is used to specify URL of the XML file from which to take the details of advertisements.
  • Alternate Text Field: Used to specify column name in table that contains alternate tex for the advertisements.
  • ImageUrlField: Used to specify column name in the table that contain Url of the image to display for the advertisements.
  • Navigate Url Field: Used to specify the column name in table that contains Url of the page to display when user clicks on the advertisements.
  • DataSource: Used to specify ID of a data source control to use as a data source for the ad rotator.
  • KeywordFilter:Used to specify a keyword based on which advertisements displayed in the ad rotator will be filtered.

Calender Control

Calender is used to display calender to the user on the page and allow the user to select a date or a range of  dates.

Properties:
  • DateNameFormat : Used to specify the format in which the week name is displayed within the calender.
  • FirstDayofWeek:Used to specify week name in which you want to start the calender.
  • SelectedDate: Used to specify the date selected within the calender.
  • Selection Mode: Used to specify whether user can select a single date or day and week or day, week and month.
Events:
  • SelectionChanged: This is the default event for the calender and it eill be raised whenever a new date is selected in the calender.
  • DayRender: This event will be raised once for every day rendered in the calender.