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.

DataGridVeiw Control

This control is used to display the data in the form of a table i.e. rows and columns. To display data in the control first we need to bind the DataTable of DataSet to the GridVeiw control by using a DataSource property as following
                  dataGridVeiw1.DataSource=<datatable>

DataGridVeiw control has a specialty ie changes performed to data in it gets reflected directly to the data of DataTable to which it was bound, so that we can update dataset back to database directly.

To test this add a new form in the project and place a DataGridVeiw control on it setting the dock property as top. Now place 2 buttons on the form setting the text as save and close


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.SqlClient;
using System.Configuration;

namespace WindowsFormsApp
{
    public partial class Form9 : Form
    {
        public Form9()
        {
            InitializeComponent();
        }
        SqlConnection con;
        SqlDataAdapter da;
        SqlCommandBuilder cb;
        DataSet ds;
        private void Form9_Load(object sender, EventArgs e)
        {
            string constr = ConfigurationManager.ConnectionStrings["SConstr"].ConnectionString;
            con = new SqlConnection(constr);
            ds = new DataSet();
            da = new SqlDataAdapter("Select Eno,Ename,Job,Salary From Employee Order By Eno", con);
            da.Fill(ds, "Employee");
            dataGridView1.DataSource = ds.Tables[0];

        }

        private void btnsave_Click(object sender, EventArgs e)
        {
            cb = new SqlCommandBuilder(da);
            da.Update(ds, "Employee");
            MessageBox.Show("Data saved to db sarver");
        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}