Tuesday, June 23, 2009

ObjectDataSource

1. Introduction
This document provides details regarding how to use objectdatasource control in
asp.net application for grid view paging using select method.

2. What is ObjectDataSource?
ObjectDataSource is a non-display control in ASP.NET 2.0 that acts as a bridge
between your data-access objects and data-bound controls on the web page.
ObjectDataSource helps the developer to reduce the code to bind data to data-bound
controls. ObjectDataSource works in stateless mode like the web itself.
ObjectDataSource can be used for CRUD operations (Create, Retrieve, Update, and
Delete). If you use ObjectDataSource to display data in the asp.net page, it calls the
‘select’ method to create an object, reads the properties from that object for the
data-bound control and disposes it before the page has completed. This article
provides a clear description of using ObjectDataSource to bind data to grid view and
paging logic.
3. How to use ObjectDataSource?
Create an ASP.NET website naming ObjectDataSourceDemo for instance. In this
sample I have used enterprise library for establishing database connection. If you are
not familiar with enterprise library you can use your own way to establish connection
to database. In the aspx page just add a grid view and an objectdatasource control
like the code below.
AutoGenerateColumns="false" AllowPaging="true" Width="835px"
OnDataBound="dgvRequests_DataBound" ShowFooter="True">

runat="server" SelectCountMethod="SelectCount" EnablePaging="true"
SelectMethod="GetRequest" TypeName="RequestData">

Set the DataSourceId property of grid view as the id of the ObjectDataSource,
In our case it is ‘objRequest’, and AllowPaging and ShowFooter to true.
Here let us know certain properties of ObjectDataSource before using them.


EnablePaging :
Gets or sets a value indicating whether the ObjectDataSource control has data
caching enabled.


SelectMethod :
Gets or sets the name of the method or function that the ObjectDataSource control
invokes to retrieve data.


SelectCountMethod:
Gets or sets the name of the method or function that the ObjectDataSource control
invokes to retrieve a row count.


TypeName:
To create an instance of the object that the ObjectDataSource control binds to, the
control uses reflection to load the type that is identified by the type name at run time.
Therefore, the value of the TypeName property can be a partially qualified type for code
that is located in the Bin or App_Code directories or a fully qualified type name for code
that is registered in the global assembly cache. If you use the global assembly cache, you
must add the appropriate reference to the assemblies section of the Machine.config or
Web.config file.


In this example I have added a class RequestData.cs in App_Code directory and so the
TypeName is specified as above. Fully qualified class name that is “namespace.Classname”
can be given in this property if the class is not placed in App_Code directory.
Let’s have a look at the SelectMethod.


public DataTable GetRequest(int maximumRows, int
startRowIndex,ObjectDataSourceSelectingEventArgs e)
{
DataTable dtRequest = null;
objBus = new objBusiness();
dtRequest = objBus.GetRequestDetail(out totalPage).Tables[0];
if (dtRequest != null && dtRequest.Rows.Count > 0)
{
Page 5 of 8
e.Arguments.TotalRowCount = totalPage;
}
return dtRequest;
}


The selectMethod must have maximumRows, startRowIndex as arguments as shown
above and return type as Datatable. GetRequestDetail is the method in base class used to
get the data from database and totalPage is the out variable of the method is the total
number of records that is to be returned from the procedure, ‘objBus’ is the instance of the
business class in order to use the method.


The ObjectDataSourceSelectingEventArgs class is used in the OnSelecting method. Because
it is derived from the ObjectDataSourceMethodEventArgs class, the
ObjectDataSourceSelectingEventArgs class provides access to input parameters for
validation and manipulation through the InputParameters property. The
ObjectDataSourceSelectingEventArgs class also provides the ExecutingSelectCount
property, which is used to check whether the currently executing data retrieval operation is
retrieving a row count, in addition to the data. This is important because when data source
paging is enabled, the Selecting event is raised twice. For more information, see
ExecutingSelectCount.


To add the argument ‘e’ in the selectMethod we have added it in InputParameters. If you
need to pass any argument in select method it is necessary to add it in OnSelecting event of
the ObjectDataSource.


public void objRequest_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
if (!e.ExecutingSelectCount)
{
e.Arguments.MaximumRows = dgvRequests.PageSize;
e.Arguments.RetrieveTotalRowCount = true;
e.InputParameters.Add("e", e);
}
}


The SelectCountMethod in the App_Code just returns the row count as shown
below.


public int SelectCount(ObjectDataSourceSelectingEventArgs e)
{
return e.Arguments.TotalRowCount;
}




To display the page count in the footer of grid view add a label in Footer template of the
grid view and assign the value in DataBound event of the grid view like the code below.
protected void dgvRequests_DataBound(object sender, EventArgs e)
{
if (dgvRequests.Rows.Count > 0)
{
lblpageString = (Label)dgvRequests.FooterRow.FindControl("lblPageString");
if (lblpageString != null)
lblpageString.Text = string.Format("Page {0} Of {1}",
this.dgvRequests.PageIndex + 1, this.dgvRequests.PageCount);
}
}
}
After this just run the asp.net application and you may see the grid view working fine
with the
paging implementation.


4. Conclusion
Thus paging logic can be implemented in grid view using ObjectDataSource.The same can also
be done to DataView control and we can also use ObjectDataSource for deleting. Updating and inserting
data in database.


Thursday, June 11, 2009

Testing Documentation for Projects

TESTING AND IMPLEMENTATION
Implementation is the final and important phase. It involves user training, system testing and successful running of the developed system and changes are made according to their needs. The testing phase involves the testing of developed system using various kinds of data.
An elaborate testing of data is prepared and the system is tested using that test data. While testing, errors are noted and corrections are made. The users are trained to operate the developed system. Both hardware and software securities are made to run the developed system successfully in future.
4.1 Testing
System testing is the stage of implementation, which is aimed at ensuring that the system works accurately and efficiently before live operation commences. Testing is vital to the success of the system. System testing makes a logical assumption that if all the parts of the system are correct, the goal will be successfully achieved. The candidate system is subject to a variety of tests: on-line response, volume, stress, recovery, and security and usability tests.
The testing steps are:
Unit testing
Integration testing
Validation
Output testing
User Acceptance testing
Testing objectives
There are several rules that can serve as testing objectives. They are,
Testing us a process of executing a program with the intent of finding an error.
A good test case is one that has high probability of finding an undiscovered error.
A successful test is one that uncovers as undiscovered error.
If testing is conducted successfully according to the objectives as stated above, it would uncover errors in the software. Generally by testing, we are verifying the following three aspects.
Testing For Correctness
Testing For Implementation Efficiency
Testing For Computational Complexity
Testing for correctness is supposed to verify that a program does exactly what it is designed to do. This is much more difficult than it may at first appear, especially for large programs. The testing is done by running the software for all correct and checking if the system reports any errors. The system is to be tested with the data at the extremes of the input range. The system is also to be tested for values outside the input range. The testing is basically done with an objective to force the system into an error. After finding an error they have to be corrected and tested again.
Test for implementation efficiency attempt to find ways to make a correct program run faster or use less storage. This is to be done by checking arithmetic operations, redundant calculation, group elimination etc. It is a code-refining process, which re-examines the implementation phase of algorithm development.
Tests for computational complexity amount to an experimental analysis of the complexity of an algorithm or an experimental comparison of two or more algorithms, which solve the same problem.
Testing is carried out in different cases. First different units are individually tested and then the system as a whole is tested. Once the system test is satisfactory completed the acceptance test us carried out, where the system is tested with clients data.
4.1.1 Unit Testing
Unit testing focuses verification efforts on the smallest unit of software design, the module. This is also known as “Module Testing”. The modules are tested separately. This testing is carried out during programming stage itself. In this testing step each module is found to be working satisfactorily as regard to the expected output from the module.
When carrying out the unit testing process that each module is working effectively and the corresponding data entry for the developer is working properly and information is transferring from each unit. And all the conditions that what given in the each module is working properly.
4.1.2 Integration Testing
Integration testing focuses on design and the construction of the software architecture. Data can be lost across an interface; one module can have adverse effect on another sub function and so on. Thus integration testing is a part that the software meets all functional, behavioral and performance requirements. The errors, which are uncovered during integration testing, are corrected during this phase.
When carrying out integration testing linking with each module is performing perfectly, and delivering the information between each designation is working properly and messaging broadcasting between all the modules is appropriate.
4.1.3 Validation Testing
Errors discovered where corrected prior to completion of this project with the help of the user by negotiating to establish a method of resolving deficiencies. Thus the proposed system under consideration has been tested by using validation testing and found to be working satisfactorily.
4.1.4 Output Testing
After performing the validation testing, the next step is output testing of the proposed system since no system could be useful if it does not produce the required output in the specific format. The outputs generated or displayed by the system under consideration are tested asking the users about the format required by them. Here, the output is considered into two ways: one is on the screen and the other is printed format.
The output format on the screen is found to be correct as the format designed according to the user needs. For the hard copy also, the output comes out as specified by the user. Hence output testing does not result in any correction in the system. Output testing leading the result we need we are getting as the output.
4.1.5 User Acceptance testing
User acceptance of a system is the key factor for the success of any system. The system under consideration is tested for user acceptance by constantly keeping in touch with the prospective system users at time of developing and making changes wherever required. This is done with regard to the following points:-
Input screen design
Output screen design
On-line message to guide the user
Menu driven system
Format of ad-hoc reports and other outputs
The above testing is done by taking various kinds of test data. Preparation of test data plays a vital role in the system testing. After preparing the test data the system under study is tested using that test data. While testing the system by using test data errors are again uncovered and corrected by using above testing steps and corrections are also noted for future use.
From the above testing that all modules like HelpDesk Master configuration, Asset configuration, Plan Management of the project have developed are tested and they have developed according to needs of the user.
By
Kannan. M. K

HTML/JAVASCRIPT BLOG

You can find the help for html and javascript codes

Any Doubts Contact my Mail-ID:
kannan.mkv@gmail.com