0% found this document useful (0 votes)
27 views

C# Unit 4-1

Uploaded by

jyothika12k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

C# Unit 4-1

Uploaded by

jyothika12k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Two marks questions

1. What is ADO.NET?
Answer: ADO stands for Active Database Object. ADO.NET is a new database technology used by .NET
platform. It is a set of classes used to communicate between an application front end and a database
2. What is data binding? Mention types of data binding.
Answer: Data binding is a powerful feature provided by the .NET framework that enables visual elements
in a client to connect to a datasource such as DataSets, DataViews etc. The process of binding the data with
the controls of the forms is known as data binding. There are two types
a. Simple data binding
b. Complex data binding
3. Differentiate simple and complex binding.
Answer:
Simple data binding Complex data binding
It binds to one data item at a time It binds to more than one data element at the same time.
Eg: binding a name displayed in a text box Eg: Binding more than one record in a database at the same
time
4. What is Data Bound control? Give example
Answer: The DataBound Control class is a class used to interact with tabular or list-style data. DataBound
controls are used to display data to the end-user within the web applications and using DataBound controls
allows you to manipulate the data within the web applications very easily. DataBound controls are
composite controls that combine other ASP.NET Controls like Text boxes, Radio buttons, Buttons and so
on.
Frequently used DataBound controls:
 Repeater
 DataList
 GridView
 List View
 Form View
5. List any four ADO.NET objects.
Answer:
1. Data connection objects
2. Data adapters
3. Command objects
4. Datasets
5. DataTable objects
6. Data readers
7. Data views
8. Constraint objects
9. DataRelation objects
10. DataRow objects
11. DataColumn objects
6. What is use of DataReader object?
Answer: DataReader objects hold a read-only, forward-only (i.e., you can only move from one record to the
succeeding record, not backwards) set of data from a database. Using a DataReader can increase speed
because only one row of data in memory at a time.

1
7. Differentiate ExecuteNonQuery and ExecuteScalar
Answer:
Method Means
ExecuteNonQuery Executes a non-row returning SQL statement, returning the number of affected
rows
ExecuteScalar Executes the command and returns the value in the first column in the first row of
the result.
8. What is dataset?
Answer: Datasets store data in a disconnected cache. The structure of a dataset is similar to that of a
relational database; it gives you access to an object model of tables, rows, and columns, and it contains
constraints and relationships defined for the dataset. Datasets are supported with DataSet objects
9. How to create Dataset and populate it with data?
Answer:
Creating a Dataset
To create a Dataset using a data adapter, you can use the Data | Generate Dataset menu item or right-click a
data adapter and choose the Generate Dataset menu item. Then select the table you want to add to the
dataset, give it a name and click OK. Doing so creates a new Dataset object.
Populating a Dataset
Datasets are disconnected from data sources, and to populate them with data, you must use a data adapter.
You can use a data adapter's Fill method to fill a dataset:
DataSet1.Clear()
SqlDataAdapter1.Fill(DataSet1)
10. What is Web server control?
Answer: Web server controls include traditional form controls such as buttons and text boxes as well as
complex controls such as tables. They also include controls that provide commonly used form functionality
such as displaying data in a grid, choosing dates, displaying menus, and so on.
11. List any four public properties of Button web server control
Answer:
CausesValidation CommandArgument CommandName OnClientClick
PostBackUrl Text UseSubmitBehavior ValidationGroup
12. What is the use of PostBackUrl and CausesValidation Property of web control?
Answer:
PostBackUrl Obtains or specifies the URL of the page to post when the Button control is clicked
CausesValidation Obtains or specifies a value indicating whether or not validation is performed when the
web control is clicked.
13. What is use of TextMode property of Textbox web control
Answer: TextMode property obtains or specifies the behavior mode (single line, multiline or password)of
the TextBox control
14. What is Validation Control? List any two.
Answer: Validation controls are the controls used for validating the data entered in an input control, such as
the TextBox control of the web page. These validation controls helps in reducing the load on the server by
eliminating the need to send every piece of data to the server for validation.
1. The RequiredFieldValidator control
2. The RangeValidator control
3. The RegularExpressionValidator control
4. The CompareValidator control
5. The CustomValidator control
6. The ValidationSummary control

2
15. Give the default syntax of asp.net source code added for Textbox web control when it is placed in
designer window.
Answer: <asp:TextBox ID=”TextBox1” runat=”server”></asp:TextBox>
16. What is use of DataBind and UpdateRow methods of GridView web control?
Answer:
DataBind Binds the data from the data source with the GridView control
UpdateRow Updates the row specified by index
17. What is use of AutoGenerateRows property of DetailsView Control?
Answer:
AutoGenerateRows Obtains or sets a value indicating whether row fields are automatically created for
each field in the data source
18. What is FormView control? List any two properties.
Answer: The FormView control displays a single record from the associated data source. Each row of the
table displays each field of the record.
Property Description
AllowPaging Gets or sets a value indicating whether the paging feature is enabled
BackImageUrl Obtains or sets the URL to an image to display in the background of a FormView
control
Caption Obtains or sets the text as a caption in a FormView control
CaptionAlign Obtains or sets the horizontal or vertical position
CellPadding Obtains or sets the amount of space between the contents of a cell and the cells
border
CellSpacing Obtains or sets the amount of space between cells
CurrentMode Obtains the current data entry mode of the FormView control
DataItemCount Obtains the number of items in the data source.
DataKeyNames Obtains or sets an array that contains the names of primary key fields for the items
displayed in a FormView control
DefaultMode Obtains or sets the default data entry mode of the FormView control
HorizontalAlign Obtains or sets the horizontal alignment of a FormView control on the page
PageCount Obtains the number of pages required to display every record in the data source.
PageIndex Obtains or sets the index of the currently displayed page.
SelectedValue Obtains the data key value of the current record
19. What is the use of Repeater web control?
Answer: The Repeater control is a data bound control that is used to display repeated list of items from the
associated data source.
20. What is the use of DataPager Control?
Answer: The DataPager control is used to provide paging functionality to the data bound controls. When
you drag a DataPager control to the page, the following code appears in the Source view of the page:

<asp:DataPager ID= “DataPager1” runat= “server”></asp:DataPager>

Long Answer Questions ( 4/5/6 Marks)

1. Explain any two ADO.NET Objects.


Answer:
a. Data connection objects—To start working with a database, you must have a data connection. A
data adapter needs a connection to a data source to read and write data, and it uses
OleDbConnection, Odbc Connection, Oracle Connection or SqlConnection objects to communicate
with a data source.
 OleDbConnection- Object Linking and Embedding Database.

3
 An OleDbConnection object represents a unique connection to a data source.
b. Data adapters—Data adapters are a very important part of ADO.NET. You use them to
communicate between a data source and a dataset. The two types of data adapters are
OleDbDataAdapter and SqlDataAdapter objects.
c. Command objects—Data adapters can read, add, update, and delete records in a data source. To
allow you to specify how each of these operations work, a data adapter contains command objects
for each of them. Data adapters support four properties that give you access to these command
objects: SelectCommand, InsertCommand, UpdateCommand, and DeleteCommand.
d. Datasets—Datasets store data in a disconnected cache. The structure of a dataset is similar to that
of a relational database; it gives you access to an object model of tables, rows, and columns, and it
contains constraints and relationships defined for the dataset. Datasets are supported with DataSet
objects
e. DataTable objects—DataTable objects hold a data table from a data source. Data tables contain
two important properties: Columns, which is a collection of the DataColumn objects that represent
the columns of data in a table, and Rows, which is a collection of DataRow objects, representing the
rows of data in a table.
f. Data readers— DataReader objects hold a read-only, forward-only (i.e., you can only move from
one record to the succeeding record, not backwards) set of data from a database.
g. Data views—Data views represent a customized view of a single table that can be filtered,
searched, or sorted.
h. Constraint objects—Datasets support constraints to check data integrity. A constraint, supported
by the Constraint class, is a rule that can be used when rows are inserted, updated, or deleted to
check the affected table after the operation. There are two types of constraints: unique constraints
check that the new values in a column are unique throughout the table, and foreign-key constraints
specify how related records should be updated when a record in another table is updated.
i. DataRelation objects—DataRelation objects specify a relationship between parent and child tables,
based on a key that both tables share.
j. DataRow objects—DataRow objects correspond to a particular row in a data table. You use the
Item property to get or set a value in a particular field in the row.
k. DataColumn objects—DataColumn objects correspond to the columns in a table. Each object has a
DataType property that specifies the kind of data each column contains, such as integers or string
values.
2. Explain Simple binding with example
Answer: Simple binding lets you to display one data element, such as a field's value from a data table, in a
control. In Visual Basic .NET, you can simple-bind any property of a control to a data value. For example,
to bind a text box's Text property to the rollnumber field in the student table from the database in a dataset,
DataSet11, you select the text box and expand its (DataBindings) property in the Properties window. You
will see the bound properties such as Tag and Text properties for a text box. You can select a field in a
dataset to bind to just by clicking a property and selecting a table from the drop-down list that appears.

Figure: Binding a text box to a data table.

4
You can bind to any property of a control. To do that, click the ellipsis button that appears when you click
the (Advanced) entry in the (DataBindings) property, opening the Advanced Data Binding dialog you see
in Figure

Figure: The Advanced Data Binding dialog


Using the Advanced Data Binding dialog, you can bind any property of a control to a data source. Note that
because simple-bound controls show only one data element at a time. It's usual to include navigation
controls in a Windows form with simple-bound controls;
The navigation controls will let the user move from record to record just by clicking buttons, and all the data
in the bound controls will be updated automatically to match.
You also can perform simple binding in code, using a control's DataBindings property.
For example, in code, we could bind the text box to the same rollnumber field that we just bound it to at
design time. Using the collection's Add method, you pass this method the property to bind, the data source
to use, and the specific field you want to bind:
TextBox1.DataBindings.Add("Text", DataSet11, " rollnumber ")
3. Explain complex data binding with example.
Answer: Complex data binding allows a control to bind to more than one data element, such as more than
one record in a database, at the same time. Using complex data binding we can bind an entire data table to a
data grid. Instead of displaying just one data item a time, the data grid displays the entire table at once,
including all the fields and field data.
Complex data binding revolves around these properties:
 DataSource— The data source, typically a dataset such as DataSet1
 DataMember— The data member you want to work with in the data source typically a table in a
dataset such as the authors table in the pubs database.
 DisplayMember— The field you want a control to display, such as the authors last name.
 ValueMember— The field you want the control to return in properties like SelectedValue, such as
au_id.
Setting the above 4 properties at run time is also easy- you just assign them a new value. Here is how we
bind the Dataset11 dataset to a list box using the DisplayMember property, using the au_fname field in
the authors table
ListBox1.DataSource=DataSet11
ListBox1.DisplayMember= “authors.au_fname”
ListBox1.ValueMember= “authors.au_id”
4. Write a note on Navigating in Datasets
Answer: You usually add navigation controls, such as the buttons at the bottom of the DataBinding to let
the user move from record to record. When the user clicks the > button, for example, the bound data from
the next field is displayed in the text box, so the name displayed in the text box changes from the first
author's last name to the last name of the next author. The >> button moves to the last record, the << button
moves to the first record, and so on.
Displaying the Current Location
Answer: When the DataBinding example first loads, it fills its dataset from its data adapter. It also displays
the current position in the dataset's binding context for the authors table by using the form's Binding
Context property's Position and Count members, like this:

5
Private Sub Form1_Load(ByVal sender As system.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11)
Label1.Text = (Me.BindingContext(DataSet11,"authors").Position + 1).ToString &
" of " & Me.BindingContext(DataSet11, "authors").Count.ToString
End Sub
Moving to the Next Record
When the user clicks the > arrow, just increment the Position property of the binding context for the
authors table, and then display the new location in the label between the navigation buttons:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Me.BindingContext(DataSet11, "authors").Position =
(Me.BindingContext(DataSet11, "authors").Position+ 1)
Label1.Text = (((Me.BindingContext(DataSet11,"authors").Position + 1).ToString
& " of ") & Me.BindingContext(DataSet11,"authors").Count.ToString)
End Sub
Note that if you try to move beyond the end of the record set, the Position property isn't incremented.
Moving to the Previous Record
In the same way, when the user clicks the < button to move to the previous record, the code simply
decrements the Position value:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Me.BindingContext(DataSet11, "authors").Position =
(Me.BindingContext(DataSet11, "authors").Position -1)
Label1.Text=(((Me.BindingContext(DataSet11,"authors").Position + 1).ToString &
" of ") & Me.BindingContext(DataSet11,"authors").Count.ToString)
End Sub
Moving to the First Record
Moving to the first record in the binding context for the authors table is easy; you just set the Position
property to 0:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Me.BindingContext(DataSet11, "authors").Position = 0
Label1.Text = (((Me.BindingContext(DataSet11, "authors").Position+ 1).ToString
& " of ") &
Me.BindingContext(DataSet11,"authors").Count.ToString)
End Sub
Moving to the Last Record
Moving to the last record is also easy, because we know that the Count property returns the total number of
records in the table:
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Me.BindingContext(DataSet11, "authors").Position = Me.BindingContext(DataSet11,
"authors").Count - 1
Label1.Text = (((Me.BindingContext(DataSet11,"authors").Position + 1).ToString
& " of ") & Me.BindingContext(DataSet11,"authors").Count.ToString)
End Sub
5. Explain SqlConnection Class
Answer: The SqlConnection class represents a connection to a SQL Server database. Here is the inheritance
hierarchy of this class:
System.Object
System.MarshalByRefObject
System.ComponentModel.Component

6
System.Data.SqlClient.SqlConnection
The public properties of SqlConnection objects are in below table.
Property Means
ConnectionString Gets/sets the connection string to open a database
ConnectionTimeout Gets the amount of time to wait trying to make a connection
Database Gets the name of the database to open
DataSource Gets the name of the SQL Server to use
PacketSize Gets the size of communication packets to use
ServerVersion Gets the version of the server
State Gets the connections current state
WorkstationID Gets the database client ID
Notable methods are given in below table
Method Means
BeginTransaction Starts a database transaction
ChangeDatabase Changes the current database
Close Closes the connection to the data provider
CreateCommand Creates an OleDbCommand object for this connection
Open Opens a database connection
Notable events are given in below table
Event Means
InfoMessage Occurs if the provider sends a message
StateChange Occurs when a connections state changes
6. Explain SqlCommand Class
Answer: The SqlCommand class represents an SQL statement or stored procedure for use in a database
using SQL Server. Here is the inheritance hierarchy of this class:
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Data.SqlClient.SqlCommand
The public properties of SqlCommand objects are in below table.
Property Means
CommandText Gets/sets the SQL statement for the command to execute
CommandTimeout Gets the amount of time to wait trying to execute a command
CommandType Gets/sets the type of the CommandText property
Connection Gets/sets the SqlConnection to use
DesignTimeVisible Gets/sets if the command object should be visible in a form designer
Parameters Gets the command parameters
Transaction Gets/sets the transaction that contains the command
UpdatedRowSource Gets/sets how results are used in a data row when you use the Update
method
Notable methods are given in below table
Method Means
Cancel Cancels a commands execution
CreateParameter Creates a new parameter

7
ExecuteNonQuery Executes a non-row returning SQL statement, returning the number of
affected rows
ExecuteReader Creates a data reader using the command
ExecuteScalar Executes the command and returns the value in the first column in the first
row of the result.
Prepare Creates a compiled version of the command
ResetCommandTimeout Resets the timeout value to the default value
7. Explain SqlDataAdapter Class
Answer: The SqlDataAdapter class represents a bridge between a dataset and an SQL Server database.
Here is the inheritance hierarchy of this class:
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Data.Common.DataAdapter
System.Data.Common.DbDataAdapter
System.Data.SqlClient.SqlDataAdapter
The public properties of SqlDataAdapter objects are in below table.
Property Means
DeleteCommand Gets/sets the SQL for deleting record
InsertCommand Gets/sets the SQL for inserting record
SelectCommand Gets/sets the SQL for selecting record
UpdateCommand Gets/sets the SQL for updating record
Notable methods are given in below table
Method Means
Fill Adds or refreshes rows to a dataset to make them match the rows in a data sets
Notable events are given in below table
Event Means
RowUpdated Occurs when a row is updated
RowUpdating Occurs when a row is being updated
8. Explain DataSet Class
Answer: The DataSet class supports datasets, which act as data caches you can access in code. Here is the
inheritance hierarchy of this class:
System.Object
System.ComponentModel.MarshalByValueComponent
System.Data.DataSet
The public properties of DataSet objects are in below table.
Property Means
CaseSensitive Gets/sets whether string comparisons are case sensitive
DataSetName Gets/sets the name of the dataset
HasErrors Indicates if there are errors in any row of any table.
Namespace Gets/sets the namespace of the dataset
Tables Gets tables in the dataset.

8
Notable methods are given in below table
Method Means
AcceptChanges Accepts the changes made to the dataset
BeginInit Begins the initialization of a dataset
Clear Clears the dataset by removing all rows in all tables
Copy Copies the dataset
EndInit Ends the initialization of a dataset
GetChanges Gets a dataset containing all changes made to the current dataset
HasChanges Indicates if the dataset has changes that have not yet been accepted
Merge Merges this dataset with another dataset
RejectChanges Rolls back the changes made to the dataset since it was created or since the
AcceptChanges method was called.
Reset Resets the dataset back to the original state
Notable events are given in below table
Event Means
MergeFailed Occurs when a Merge operation fails
9. Explain SqlDataReader Class
Answer: The SqlDataReader class creates a data reader for use with the SQL Server. Here is the
inheritance hierarchy of this class:
System.Object
System.MarshalByRefObject
System.Data.SqlClient.SqlDataReader
The public properties of SqlDataReader objects are in below table.
Property Means
Depth Gets the current row’s nesting depth
FieldCount Gets the number of columns in the current row
IsClosed Indicates if a data reader is closed
Item Gets the value in a field
RecordsAffected Gets the number of rows changes, inserted or deleted by SQL statement
Notable methods are given in below table
Method Means
Close Closes the data reader
GetBoolean Gets a field’s value as a Boolean
GetByte Gets a field’s value as a byte
GetBytes Reads a stream of bytes
GetChar Gets a field’s value as a single character
GetChars Reads a stream of characters
GetDateTime Gets a fields value as a DateTime object
GetDecimal Gets a field’s value as a Decimal
GetDouble Gets a field’s value as a double-precision floating point number
GetFloat Gets a field’s value as a float
GetString Gets a field’s value as a string

9
10. Explain web button control with any five public properties
Answer: The Button control is used to create a button that sends a request to a Web page. This control
exists within the System.Web.UI.WebControls namespace. It posts data to the server when it is clicked. The
class hierarchy of the Button class is as follows:
System.Object
System.Web.UI.Control
System.Web.UI.Webcontrols.Webcontrol
System.Web.UI.Webcontrols.Button
The below table shows properties of the Button class
Property Description
CausesValidation Obtains or specifies a value indicating whether or not validation is performed when
the Button control is clicked
CommandName Obtains or specifies the command name associated with the Button control
OnClientClick Obtains or specifies the client side script that executes when a Button control’s Click
event is raised
PostBackUrl Obtains or specifies the URL of the page to post when the Button control is clicked
Text Obtains or specifies the text to be displayed on the Button control
ValidationGroup Obtains or specifies the group of controls for which the Button control causes
validation when it posts back to the server
The public events of the Button class are listed in below table
Event Description
Click Occurs when the Button control is clicked
Command Occurs when the Button control is clicked. This event helps you to create multiple Button
controls on a Web page and then it programmatically determines which Button control has
been clicked
The Button controls are used to create push buttons on a Web page. Push buttons can be either Submit
buttons or Command buttons. By default, a Button control is a Submit button. A Submit button does not
have a command name element. You can provide an event handler with the Click event to programmatically
control the actions performed when the Submit button is clicked.
A Command button has a command name associated with the button, which you need to specify by using
the CommandName property, such as Sort. This allows you to create multiple Button controls on a Web
page and programmatically find out which of the Button is clicked.
11. Explain following validation controls
i. The RequiredFieldValidator control
ii. The RangeValidator control
iii. The RegularExpressionValidator control
iv. The CompareValidator control
v. The CustomValidator control
vi. The ValidationSummary control
Answer:
i. The RequiredFieldValidator Control: The RequiredFieldValidator control is the simplest control and
is used to ensure that the user has entered the data into the input control, such as TextBox to which it is
bound. If you do not enter any value, the Validation control displays an error message. The inheritance
hierarchy for the RequiredFieldValidator class is:
System.Object
System.Web.UI.Control
System.Web.UI.Webcontrols.Webcontrol

10
System.Web.UI.Webcontrols.Label
System.Web.UI.Webcontrols.BaseValidator
System.Web.UI.Webcontrols.RequiredFieldValidator
The RequiredFieldValidator class has no non-inherited methods or events and it inherits many of the
properties and methods of the BaseValidator class that are listed in below table. The public property of the
RequiredFieldValidator class is:
Property Description
InitialValue Handles the initial value of the associated input control
ii. The RangeValidator Control: The RangeValidator control checks whether or not the value of an input
control is inside a specified range of values. It has the following three properties:
 ControlToValidate : Contains the input control to validate
 MinimumValue: Holds the minimum value of the valid range
 MaximumValue: Holds the maximum value of the valid range
If one of these properties is set, then the other property must also be set. Do not forget to set the Type
property to the data type of the values. The following data types can be used for the values:
String: A string data type
Integer: An integer data type
Double: A double data type
Date: A date data type
Currency: A currency data type
The inheritance hierarchy for the RangeValidator class is:
System.Object
System.Web.UI.Control
System.Web.UI.Webcontrols.Webcontrol
System.Web.UI.Webcontrols.Label
System.Web.UI.Webcontrols.BaseValidator
System.Web.UI.Webcontrols.BaseCompareValidator
System.web.UI.WebControls.RangeValidator
The public properties of the RangeValidator class are:
Property Description
MaximumValue Obtains or specifies the maximum value of the validation range for the controls
specified in the RangeValidator control
MinimumValue Obtains or specifies the minimum value of the validation range for the controls
specified in the RangeValidator control
iii. The RegularExpressionValidator Control: Regular expressions are used to check whether or not the
text matches a certain pattern. The RegularExpressionValidator control validates whether the value in
the input control (textbox) matches the format specified by the regular expression. The
RegularExpressionValidator control exists within the System.Web.UI.WebControls namespace.
In general, regular expressions are made up of text with an embedded code that starts with a backslash
(\). The following is an example:
\b[A-Za-z]+\b
The above regular expression matches a word consisting of uppercase or lowercase letters only. The +
sign matches the previous character or the sub expression one or more times, so we are matching one or
more uppercase and/or lowercase letters here.
The inheritance hierarchy for the RegularExpressionValidator class is:
System.Object
System.Web.UI.Control
System.Web.UI.Webcontrols.Webcontrol
System.Web.UI.Webcontrols.Label
System.Web.UI.Webcontrols.BaseValidator

11
System.Web.UI.Webcontrols.RegularExpressionValidator
The property of the RegularExpressionValidator class is listed in below table
Property Description
ValidationExpression Obtains or specifies the regular expression that you want to match data for
validation
iv. The CompareValidator control
The CompareValidator control is used to compare the value entered by a user into one input control
with the value entered into another input control or with an already existing value. The
CompareValidator control exists within the System.Web.UI.WebControls namespace. The below table
lists the various Operator property types, specifying the different types of comparisons:
Type Description
Equal Checks whether the compared values are equal
NotEqual Checks that controls are not equal to each other
GreaterThan Checks for a greater than relationship
GreaterThanEqual Checks for a greater than or equal to relationship
LessThan Checks for a less than relationship
LessThanEqual Checks for a less than or equal to relationship
The Type property is used to specify the data type of both the comparison values, where String is the
default type. Both values are automatically converted to the String type before the comparison operation
is performed. The different data types that can be used are as follows:
 String: A string data type
 Integer: An integer data type
 Double: A double data type
 Date: A date data type
 Currency: A currency data type
The properties are:
Property Description
ControlToCompare Obtains or specifies the data entry control, which has to be compared with the
data entry control being validated
Operator Obtains or specifies the comparison operation to perform
ValueToCompare Obtains or specifies a constant value to compare with the value entered by a
user in the data entry control being validated
v. The CustomValidator control
The CustomValidator control is used to customize and implement data validation as per your requirement.
For example, if you want to find out whether a number is odd or even, you cannot use an existing Validation
control for doing that because this functionality is not included in any of the Validation controls. To solve
this problem, you need a Validation control that can be customized to solve this problem. The
CustomValidator control exists within the System.Web.UI.WebControls namespace. The inheritance
hierarchy for the CustomValidator class is:
System.Object
System.Web.UI.Control
System.Web.UI.Webcontrols.Webcontrol
System.Web.UI.Webcontrols.Label
System.Web.UI.Webcontrols.BaseValidator
System.Web.UI.Webcontrols.CustomValidator
The CustomValidator control checks whether or not the input you have given, such as prime, even or odd
number, matches a given condition. The properties are:
Property Description
ClientValidationFunction Obtains or specifies the name of the custom client side script function used

12
for validation
ValidateEmptySet Obtains or specifies a Boolean value indicating whether empty text should
be validated or not.
The events are:
Event Description
ServerValidate Occurs when validation takes place on the server
vi. The ValidationSummary control
It collects all the validation control error messages and displays it collectively on the screen. The display of
the summary, which can be a list, a bulleted list or a single paragraph, can be set by using the DisplayMode
property. You can also specify whether the summary should be displayed in the Web page or in a message
box by setting the ShowSummary and ShowMessageBox properties, respectively. The ValidationSummary
control exists within the System.Web.UI.WebControls namespace. The inheritance hierarchy for the
ValidationSummary class is:
System.Object
System.Web.UI.Control
System.Web.UI.Webcontrols.Webcontrol
System.Web.UI.Webcontrols.ValidationSummary
The properties are:
Property Description
DisplayMode Obtains or specifies the display mode
EnableClientScript Obtains or specifies a value indicating whether ValidationSummary control
updates itself using the client side script
ForeColor Obtains or specifies the foreground color of the control
HeaderText Obtains or specifies the header text displayed at the top of the summary
ShowMessageBox Obtains or specifies a value showing whether the validation summary is displayed
in a message box
ShowSummary Obtains or specifies a value showing whether the validation summary is displayed
in line
ValidationGroup Obtains or specifies the group of controls for which the ValidationSummary
object displays validation messages
12. Explain any five properties of GridView web control
Answer: The GridView control is a data bound control that displays the values of a data source in the form
of a table. In this table, each column represents a field and each row represents a record. The GridView
control exists within the System.Web.UI.WebControls namespace.
When you drag and drop the GridView control on the designer page, the following syntax is added to the
source view of the page:
<asp:GridView ID=“GridView1” runat=“server”></asp:GridView>
The below table lists the different properties:
Property Description
AllowSorting Obtains or sets a value indicating whether the sorting feature is enabled
AutoGenerateColumns Obtains or sets a value indicating whether bound fields are automatically created
for each field in the data source
BackImageUrl Obtains or sets the URL to an image to display in the background of a GridView
control
Caption Obtains or sets the text as a caption in a GridView control
CaptionAlign Obtains or sets the horizontal or vertical position

13
CellPadding Obtains or sets the amount of space between the contents of a cell and the cells
border
CellSpacing Obtains or sets the amount of space between cells
DataKeyNames Obtains or sets an array that contains the names of primary key fields for the items
displayed in a GridView control
EditIndex Obtains or sets the index of the row to edit
GridLines Obtains or sets the gridline style for GridView control
HorizontalAlign Obtains or sets the horizontal alignment of a GridView control on the page
PageCount Obtains the number of pages required to display the records of the data source in a
GridView control
PageIndex Obtains or sets the index of the currently displayed page
PageSize Obtains or sets the number of record to display on a page in a GridView control
SelectedIndex Obtains or sets the index of the selected row
SelectedRow Obtains the selected row
SelectedValue Obtains the data key value of the selected row
SortDirection Obtains the sort direction of the column being sorted
13. Explain any four methods of GridView web control
Answer:
Method Description
DataBind Binds the data from the data source with the GridView control
DeleteRow Deletes the record present at the specified location
IsBindableType Determines whether the particular data type can bind to a field
Sort Sort the GridView control according to the sort expression and direction specified
UpdateRow Updates the row specified by index
14. Explain any five properties of DetailsView web control
Answer: The DetailsView control is a data bound that is used to display a single record from the associated
data source in a table format, where each row of the table represents a field of the record. The DetailsView
control uses the DataSourceID property to support two-way binding. It also supports insert, update and
delete operations. The DetailsView control exists within the System.Web.UI.WebControls namespace. The
properties are:
Property Description
AllowPaging Gets or sets a value indicating whether the paging feature is enabled
AutoGenerateRows Obtains or sets a value indicating whether row fields are automatically created for
each field in the data source
BackImageUrl Obtains or sets the URL to an image to display in the background of a DetailsView
control
Caption Obtains or sets the text as a caption in a DetailsView control
CaptionAlign Obtains or sets the horizontal or vertical position
CellPadding Obtains or sets the amount of space between the contents of a cell and the cells
border
CellSpacing Obtains or sets the amount of space between cells
CurrentMode Obtains the current data entry mode of the DetailsView control
DataItemCount Obtains the number of items in the data source.
DataKeyNames Obtains or sets an array that contains the names of primary key fields for the items
displayed in a DetailsView control
DefaultMode Obtains or sets the default data entry mode of the DetailsView control
GridLines Obtains or sets the gridline style for DetailsView control

14
HorizontalAlign Obtains or sets the horizontal alignment of a DetailsView control on the page
PageCount Obtains the number of records in a DetailsView control
PageIndex Obtains or sets the index of the currently displayed record
SelectedValue Obtains the data key value of the current record
15. Explain any four methods of DetailsView web control
Answer:

Method Description
ChangeMode Used to switch to the specified mode
DataBind Used to bind data from the data source to the control
DeleteItem Deletes the current record from the data source
InsertItem Inserts the current record in the data source
IsBindableType Determines whether the particular data type can bind to a field
UpdateItem Updates the current record in the data source

15

You might also like