Professional Documents
Culture Documents
CheckBox
RadioButtonList,
CheckBoxList,ListBox, andDropDownList
When the events are raised, you need to handle them for
processing. The procedures that are executed when an event occurs
are called event handlers
Event handlers are automatically created when you double-click the
control in Design mode of the form. For example, the following
code is generated when you double-click a Button control whose
ID is RegisterButton. You can then write the code in the event
handler to perform the intended task.
End Sub
HANDLING POST BACK
The Web Forms page is posted back to the server only when a
Button, LinkButton, or ImageButton ASP.NET server control is
clicked. After the page is posted to the server, it is processed
there. You can respond to a button event in one of the
following ways:
Write the event handler for the Load event of the Web Forms
page. The Load event is generated when the form is loaded
from the server to the client (browser).
To implement this, the Web Forms framework provides the
following options:
The State Bags: Every page has a state bag that stores values
to be restored in the next round trip.
The framework automatically stores and restores page information
with each round trip. So, you do not need to worry about storing
and restoring the page information with each round trip.
Step 1 – Open the Visual Studio –> Create a new empty Web
application.
step 4 – go to Add New Item –> Add New XML File in project
for write advertisement detail.
<Ad>
<ImageUrl>img/2.png</ImageUrl>
<NavigateUrl>http://meera.com</NavigateUrl>
<AlternateText>Meerta Aademy</AlternateText>
<Impressions>100</Impressions>
<Keyword>Academy</Keyword>
</Ad>
<Ad>
<ImageUrl>img/3.png</ImageUrl>
<NavigateUrl>http://meeraacademy.com</NavigateUrl>
<AlternateText>Meerta Aademy</AlternateText>
<Impressions>50</Impressions>
<Keyword>Academy</Keyword>
</Ad>
</Advertisements>
NOW, ASSIGN THE XML FILE TO ADROTATOR
CONTROL BY ADVERTISEMENTFILE PROPERTY
OF ADROTATOR CONTROL.
HOW TO USE ADROTATOR CONTROL IN ASP.NET
C#.
CALENDAR CONTROL
The calendar control is a functionally rich web control, which
provides the following capabilities:
</asp:Calender>
PROPERTIES AND EVENTS OF THE CALENDAR
CONTROL
CaptionAlign
CellPadding
CellSpacing
DayHeaderStyle
DayNameFormat
DayStyle
SelectedDate
SelectedDates
SelectedDayStyle
SelectionMode
SelectMonthText
The Calendar control has the following three most important
events that allow the developers to program the calendar
control. They are:
Events
SelectionChanged
DayRender
VisibleMonthChanged
WORKING WITH THE CALENDAR CONTROL
Calendar controls allow the users to select a single day, a week,
or an entire month. This is done by using the SelectionMode
property. This property has the following values:
Properties
Day
DayWeek
DayWeekMonth
None
The syntax for selecting days:
</asp:Calender>
The following example demonstrates selecting a date and displays the date in a label:
The content file code is as follows:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="calendardemo._Default" %>
<!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>
Untitled Page
</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3> Your Birthday:</h3>
<asp:Calendar ID="Calendar1" runat="server SelectionMode="DayWeekMonth" onselectionchanged="Calendar1_SelectionChanged">
</asp:Calendar>
</div>
<p>Todays date is:
<asp:Label ID="lblday" runat="server"></asp:Label>
</p>
<p>Your Birday is:
<asp:Label ID="lblbday" runat="server"></asp:Label>
</p>
</form>
</body>
</html>
The event handler for the event SelectionChanged:
Protected void Calendar1_SelectionChanged(object
sender, EventArgs e)
{
lblday.Text =
Calendar1.TodaysDate.ToShortDateString();
lblbday.Text =
Calendar1.SelectedDate.ToShortDateString();
}
ASP.NET MULTIVIEW CONTROL
<body>
<form id="form1" runat="server">
<div>
<table align="center" class="style1" style="border: thin solid #008080">
<tr>
<td class="style2"
style="text-align: center; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: #008080;">
MultiView Control in ASP.Net</td>
</tr>
<tr>
<td style="text-align: center">
<asp:Button ID="btnview1" runat="server" onclick="btnview1_Click"
style="font-weight: 700" Text="View1" />
BackgroundImage
BackgroundImageLayout
Collapses all the nodes including all child nodes in the tree
view control.
ExpandAll
GetNodeAt
GetNodeCount
Sort
AfterCollapse
AfterExpand
AfterSelect
BeforeCheck
Checked
Gets the shortcut menu that is associated with this tree node.
ContextMenuStrip
Gets or sets the shortcut menu associated with this tree node.
EXAMPLE
IN THIS EXAMPLE, LET US CREATE A TREE
VIEW AT RUNTIME
TABSTRIP CONTROL
The TabStrip control is used to present tabbed controls,
which can be used along with the MultiPage control to
display varied information in a given space.
<tagprefix:Tab text="Node1.1"/>
<tagprefix:Tab text="Node1.2">
</tagprefix:Tab>
</tagprefix:TabStrip>
PROPERTIES OF THE TABSTRIP
CONTROL
AutoPostBack
Defaul
Orientation Style…etc.,
<tagprefix:Toolbar ..>
<tagprefix:ToolbarSeparator />
</tagprefix:Toolbar>
The Toolbar control is a container control that contains
elements to define a toolbar. These elements are described as
follows:
ToolbarButton: Defines a button on the toolbar.
DefaultStyle
SelectedStyle
Orientation
Maintainability
• DataRow
• DataColumn
• DataRelation
DataSet Object :
CommandBuilder DataReader
DataAdapter
Connection Object:
Command Object:
It is used for updating changed data, filling data sets and other
operations.
The ADO.NET Object Model is primarily divided into two
levels:
The Managed Data Providers include classes that can be used for the
following:
OleDbConnection
OleDbCommand
OleDbDataReader
OleDbDataAdapter
OleDbParameter
OleDbError
ADO.NET CLASSES FOR SQL SERVER
SqlConnection
SqlDataAdapter
SqlCommand
SqlParameter
SqlError
SqlConnection("server=localserver;uid=sa;pwd=;database=Sales")
Dim command As New SqlDataAdapter("SELECT * FROM Products
Where ProductID=@ID", connection)
connection is a SqlConnection class object that
represents a connection to the SQL Server database.
{
con.Open();
{
{
sda.Fill(ds);
}
Data Table
protected void BindGridview()
{
sda.Fill(dt);
}
ExecuteNonQuery
ExecuteNonQuery method is used to execute SQL
Command or the storeprocedure performs, INSERT,
UPDATE or Delete operations. It doesn't return any data
from the database. Instead, it returns an integer
specifying the number of rows inserted, updated or
deleted.
ExecuteReader:
}
Reader
public class Sample
{
public string Test(int Id)
{
SqlConnection sqlCon = null;
String SqlconString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionS
tring;
using (sqlCon = new SqlConnection(SqlconString))
{
sqlCon.Open();
SqlCommand Cmnd = new SqlCommand("SELECT *FROM TABLE_NAME WHERE ID=@ID", sql
Con);
Cmnd.Parameters.AddWithValue("@ID", Id);
SqlDataReader rdr = Cmnd.ExecuteReader();
while (rdr.Read())
{
string name = rdr["Name"].ToString();
string age = rdr["Age"].ToString();
string city = rdr["City"].ToString();
}
sqlCon.Close();
}
return "";
}
}
Nonquery
public class Sample
{
public void Test(int Id, string Name)
{
SqlConnection sqlCon = null;
String SqlconString = ConfigurationManager.ConnectionStrings["SqlConnec
tionString"].ConnectionString;
using (sqlCon = new SqlConnection(SqlconString))
{
sqlCon.Open();
SqlCommand Cmnd = new SqlCommand("PROC_NAME", sqlCon);
Cmnd.CommandType = CommandType.StoredProcedure;
Cmnd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = Id;
Cmnd.Parameters.AddWithValue("@NAME", SqlDbType.NVarChar).Value
= Name;
int result= Cmnd.ExecuteNonQuery();
sqlCon.Close();
}
}
A DATATABLE CONSISTS OF THE FOLLOWING
THE DATA ACCESS CLASSES OF ADO.NET
DataSet
Represents a complete collection of tables, relationships, and
constraints.
Data Adapter
Represents a database query or stored procedure that is used to
populate the DataSet object.
DataTable
Represents a data source that stores data in row and column format.
System.Data.OleDb.OleDbCommand class
This class encapsulates the commands that need to be sent to the
OLE DB data source. Applications use the OleDbCommand class to
create select, insert, update, and delete commands.
System.Data.OleDb.OleDbDataReader class
This class is very useful to all applications that want to retrieve data
returned from a query to the database and want to process one record
at a time.
System.Data.OleDb.OleDbDataAdapter class
The data adapter acts as the conduit between the client