GridView RowCommand Event
The RowCommand event is raised when a button is clicked in the GridView control. This enables you to provide an event-handling method that performs a custom routine whenever this event occurs.
The GridView control also raises other specialized events when certain buttons are clicked; means buttons with the CommandName property set to "Delete", "Update", "Page" etc…
When using one of these buttons, you should consider handling one of the specialized events provided by the control; such as RowDeleted or RowDeleting.
We will discuss more about these specialized events later.
protected void gvProjects_RowCommand(object sender, GridViewCommandEventArgs e)
{
}
The above example shows a sample RowCommand event handling method.
A GridViewCommandEventArgs object is passed to the event-handling method, which allows you to determine the command name and command argument of the button clicked. To determine the command name and command argument, use the CommandName and CommandArgument properties, respectively. You can also access the button control that raised the event by using the CommandSource property.
To find index of row, which caused this event, we can use any of the following method:
1. We can use e.CommandArgument property to find row index. ( It will work only if we didn’t set the CommandArgument property of button which we clicked)
Eg:
int index = Convert.ToInt32(e.CommandArgument);
2. Second way is, we can find index from e.CommandSource property. See the following example to know more about it
Eg:
LinkButton lbtn = (LinkButton)e.CommandSource; // get event caused button
GridViewRow gvrow = (GridViewRow)lbtn.NamingContainer; // get grid row contains event caused button
int index = gvrow.RowIndex;
Hope It will help you to handle GridView's RowCommand Event.
Wednesday, August 11, 2010
Tuesday, August 10, 2010
Creating a Database
Database
A database is a collection of information that is organized so that it can easily be accessed, managed, and updated.
create a database:
syntax: create database database_name
Eg: CREATE DATABASE TEST
database_name is the name of the database. The maximum size of a database name is 128 characters.
SQL server has two operating system file types:
1. Data files (has extension .mdf)
2. Log files ( has extension .ldf)
Data files contain data and objects such as tables and indexes. Log files contain transaction log for recovering the database transactions.
Specifying the data file and log file
Eg:
CREATE DATABASE DBTEST
ON
(
NAME='DBTESTDATA',
FILENAME='E:\jobin\database\DBTESTDATA.mdf',
SIZE=10mb,
MAXSIZE=100mb,
FILEGROWTH=10mb
)
LOG ON
(
NAME='DBTESTLOG',
FILENAME='E:\jobin\database\DBTESTLOG.ldf',
SIZE=5mb,
MAXSIZE=50mb,
FILEGROWTH=5mb
)
A database is a collection of information that is organized so that it can easily be accessed, managed, and updated.
create a database:
syntax: create database database_name
Eg: CREATE DATABASE TEST
database_name is the name of the database. The maximum size of a database name is 128 characters.
SQL server has two operating system file types:
1. Data files (has extension .mdf)
2. Log files ( has extension .ldf)
Data files contain data and objects such as tables and indexes. Log files contain transaction log for recovering the database transactions.
Specifying the data file and log file
Eg:
CREATE DATABASE DBTEST
ON
(
NAME='DBTESTDATA',
FILENAME='E:\jobin\database\DBTESTDATA.mdf',
SIZE=10mb,
MAXSIZE=100mb,
FILEGROWTH=10mb
)
LOG ON
(
NAME='DBTESTLOG',
FILENAME='E:\jobin\database\DBTESTLOG.ldf',
SIZE=5mb,
MAXSIZE=50mb,
FILEGROWTH=5mb
)
Introduction to Windows Presentation Foundation (WPF)
Windows Presentation Foundation
Windows Presentation Foundation (WPF) is the successor of Windows Forms for desktop application development. WPF applications differ from traditional Windows Forms applications in several ways. The most notable is that the code for the user interface is separate from the code for application functionality. The user interface of a WPF application is typically defined using a relatively new declarative syntax called Extensible Application Markup Language (XAML).
Selecting an Application Type
WPF development supports three kinds of application: Windows applications, Navigation applications, and XAML Browser Applications (XBAP).
Windows applications are Microsoft Windows-driven and provide a user experience that is familiar to Windows users and developers alike. Multiple windows can be open at any given time, and there is built in sense of navigation or history.
Navigation applications provide a page based user experience, similar to the experience of using a Web site. Typically, only a single page can be open at any given time, and the journal functionality keeps a record of pages visited and allows back-and-fourth navigation. Unlike a Web site, however, a Navigation application is a compiled application, has full access to the resources of your computer.
XABPs are similar to Navigation applications, but they are designed to run in Windows Internet Explorer. These applications can be deployed to a server or to a Web site and are downloaded when instantiated. Applications of this type do not have full access to a computer’s resources. XBAPs run under partial-trust environment, and resources such as the file system and the registry are inaccessible by XBAPs.
Windows Applications
A Windows Application consists of one or more windows and the associated business logic. The top level user interface (UI) element of a window is a class that derives from the Window class. The Window class derives from ContentControl, meaning that it can contain a single element in its Content property. This element is usually a layout control, such as a Grid control, which can itself contain multiple child controls.
Navigation Application
Navigation applications allow you to provide a different style of user interface to users. A navigation application is a desktop application that uses Page objects as its primary object instead of Window objects. Like Window objects, Page objects can contain a single control.
Page-based navigation applications are hosted automatically in a Navigation Window at startup. The Navigation Window provides some built in functionality for navigating through the pages of an application, such as Back and Forward buttons, and the journal, which keeps track of the pages that have been visited recently.
XBAPs
XBAPs are similar to Navigation applications. They use Page objects as the top-level UI object, and they allow a page-based navigation model that is similar to the experience of using a Web page. The primary difference between XNAP and a Navigation application is that XBAPs are not installed. They are designed to run in Internet Explorer and do not require the user to copy them onto the hard drive.
You cannot perform the following actions in an XBAP
• Access the file system, except for isolated storage
• Access the registry
• Create stand-alone windows, such as dialog boxes.
• Access local databases
• Use Windows drag-and-drop functionality
• Use WCF Web services.
Windows Presentation Foundation (WPF) is the successor of Windows Forms for desktop application development. WPF applications differ from traditional Windows Forms applications in several ways. The most notable is that the code for the user interface is separate from the code for application functionality. The user interface of a WPF application is typically defined using a relatively new declarative syntax called Extensible Application Markup Language (XAML).
Selecting an Application Type
WPF development supports three kinds of application: Windows applications, Navigation applications, and XAML Browser Applications (XBAP).
Windows applications are Microsoft Windows-driven and provide a user experience that is familiar to Windows users and developers alike. Multiple windows can be open at any given time, and there is built in sense of navigation or history.
Navigation applications provide a page based user experience, similar to the experience of using a Web site. Typically, only a single page can be open at any given time, and the journal functionality keeps a record of pages visited and allows back-and-fourth navigation. Unlike a Web site, however, a Navigation application is a compiled application, has full access to the resources of your computer.
XABPs are similar to Navigation applications, but they are designed to run in Windows Internet Explorer. These applications can be deployed to a server or to a Web site and are downloaded when instantiated. Applications of this type do not have full access to a computer’s resources. XBAPs run under partial-trust environment, and resources such as the file system and the registry are inaccessible by XBAPs.
Windows Applications
A Windows Application consists of one or more windows and the associated business logic. The top level user interface (UI) element of a window is a class that derives from the Window class. The Window class derives from ContentControl, meaning that it can contain a single element in its Content property. This element is usually a layout control, such as a Grid control, which can itself contain multiple child controls.
Navigation Application
Navigation applications allow you to provide a different style of user interface to users. A navigation application is a desktop application that uses Page objects as its primary object instead of Window objects. Like Window objects, Page objects can contain a single control.
Page-based navigation applications are hosted automatically in a Navigation Window at startup. The Navigation Window provides some built in functionality for navigating through the pages of an application, such as Back and Forward buttons, and the journal, which keeps track of the pages that have been visited recently.
XBAPs
XBAPs are similar to Navigation applications. They use Page objects as the top-level UI object, and they allow a page-based navigation model that is similar to the experience of using a Web page. The primary difference between XNAP and a Navigation application is that XBAPs are not installed. They are designed to run in Internet Explorer and do not require the user to copy them onto the hard drive.
You cannot perform the following actions in an XBAP
• Access the file system, except for isolated storage
• Access the registry
• Create stand-alone windows, such as dialog boxes.
• Access local databases
• Use Windows drag-and-drop functionality
• Use WCF Web services.
Named Parameters with Example
Named Parameters
Named arguments free you from the need to remember or to look up the order of parameters in the parameter lists of called methods. The parameter for each argument can be specified by parameter name.
Eg:
class Employee
{
public void Create(string name, string job="Software Engineer", int salary=50000)
{
}
}
When we calling the above method we can use named parameters feature
obj.Create("Jobin John", salary : 80000);
Hope now it is clear the term Named Parameters.
Named arguments free you from the need to remember or to look up the order of parameters in the parameter lists of called methods. The parameter for each argument can be specified by parameter name.
Eg:
class Employee
{
public void Create(string name, string job="Software Engineer", int salary=50000)
{
}
}
When we calling the above method we can use named parameters feature
obj.Create("Jobin John", salary : 80000);
Hope now it is clear the term Named Parameters.
Optional Parameters with Example
Optional Parameters
Optional parameters allow you to omit arguments to member invocations, whereas named arguments is a way to provide an argument using the name of the corresponding parameter instead of relying on its position in the parameter list.
Eg:
class Employee
{
public void Create(string name, string job="Software Engineer", int salary=50000)
{
}
}
The above class contains a method Create, it has three parameters. It allows to call this method like as following
obj.Create("Jobin John");
Other two parameters declared as optional parameteds, so if we doesn't suppy values for it, automatically takes initialized values of that parameters.
Optional parameters allow you to omit arguments to member invocations, whereas named arguments is a way to provide an argument using the name of the corresponding parameter instead of relying on its position in the parameter list.
Eg:
class Employee
{
public void Create(string name, string job="Software Engineer", int salary=50000)
{
}
}
The above class contains a method Create, it has three parameters. It allows to call this method like as following
obj.Create("Jobin John");
Other two parameters declared as optional parameteds, so if we doesn't suppy values for it, automatically takes initialized values of that parameters.
The dynamic type
The dynamic type
C# 4.0 introduces a new static type called dynamic. When you have an object of type dynamic you can “do things to it” that are resolved only at runtime:
dynamic d = GetDynamicObject(…);
d.M(7);
The C# compiler allows you to call a method with any name and any arguments on d because it is of type dynamic. At runtime the actual object that d refers to will be examined to determine what it means to “call M with an int” on it.
The type dynamic can be thought of as a special version of the type object, which signals that the object can be used dynamically. It is easy to opt in or out of dynamic behavior: any object can be implicitly converted to dynamic, “suspending belief” until runtime. Conversely, there is an “assignment conversion” from dynamic to any other type, which allows implicit conversion in assignment-like constructs:
dynamic d = 7; // implicit conversion
int i = d; // assignment conversion
C# 4.0 introduces a new static type called dynamic. When you have an object of type dynamic you can “do things to it” that are resolved only at runtime:
dynamic d = GetDynamicObject(…);
d.M(7);
The C# compiler allows you to call a method with any name and any arguments on d because it is of type dynamic. At runtime the actual object that d refers to will be examined to determine what it means to “call M with an int” on it.
The type dynamic can be thought of as a special version of the type object, which signals that the object can be used dynamically. It is easy to opt in or out of dynamic behavior: any object can be implicitly converted to dynamic, “suspending belief” until runtime. Conversely, there is an “assignment conversion” from dynamic to any other type, which allows implicit conversion in assignment-like constructs:
dynamic d = 7; // implicit conversion
int i = d; // assignment conversion
Subscribe to:
Posts (Atom)