MVC Web grid with column with line break

public ActionResult EmployeeTaskReport()
using (DataAccessLayer.DatabaseContext db = new DataAccessLayer.DatabaseContext())
int UserLoginID = UserRepository.GetLoginUserID();
var UserTaskList = db.TaskMasters.Where(_ => _.LoginID.Value.Equals(UserLoginID)).ToList();
ViewBag.TaskStatus = db.TaskStatusMasters.ToList();
ViewBag.SchoolName = db.SchoolMasters.ToList();
ViewBag.ProjectName = db.ProjectMasters.ToList();
//return View(UserTaskList);

List lstERTVM = new List();
foreach (TaskMaster tm in UserTaskList)
lstERTVM.Add(new EmployeeTaskReportViewModel { TMaster = tm });
return View(lstERTVM);


public class EmployeeTaskReportViewModel
public TaskMaster TMaster { get; set; }

public string TaskReportDetail;

public string _TaskReportDetail
get {
TaskReportDetail += “TaskName: ” + Convert.ToString(this.TMaster.TaskName) + “\r\n”;
TaskReportDetail += “SchoolName: ” + (this.TMaster.SchoolMaster == null ? “” : Convert.ToString(this.TMaster.SchoolMaster.SchoolName)) + “\r\n”;
TaskReportDetail += “ProjectName: ” + (this.TMaster.ProjectMaster == null ? “” : Convert.ToString(this.TMaster.ProjectMaster.ProjectName)) + “\r\n”;
return TaskReportDetail;
set { TaskReportDetail = value; }

Web grid in View______________

WebGrid grid = new WebGrid(Model);
tableStyle: “grid”,
fillEmptyRows: false,
headerStyle: “gvHeading”,
alternatingRowStyle: “gvAlternateRow”,
rowStyle: “gvRow”,
footerStyle: “gvFooter”,

mode: WebGridPagerModes.All,
firstText: “<< First",
previousText: "”,
lastText: “Last >>”,
columns: new[] {

grid.Column(“Sr.No.”, format: item => item.WebGrid.Rows.IndexOf(item)+1),
grid.Column(“Review”, format: (item) =>
string review = item._TaskReportDetail ?? “”;
return new HtmlString(review.Replace(“\r\n”, “

grid.Column(“ContactusId”, header: “Action”, canSort:false,

format: @



How to handle exceptions in SQL Server?

To handle exceptions in SQL Server we can use TRY…… CATCH blocks. To use TRY…… CATCH blocks in stored procedure we need to write the query like as shown below



—Write Your Code



—Write Code to handle errors


In TRY block we will write our queries and in CATCH block we will write code to handle exceptions. In our SQL statements if any error occurs automatically it will move to CATCH block in that we can handle error messages. To handle error messages we have defined Error Functions in CATCH block those are

ERROR_LINE() – This function will return error line number of SQL query which cause to raise error.

ERROR_NUMBER() – This function will return error number which is unique and assigned to it.

ERROR_SEVERITY() – This function will return severity of error which indicates how serious the error is. The values are between 1 and 25.

ERROR_STATE() – This function will return state number of error message which cause to raise error.

ERROR_PROCEDURE() – This function will return name of the procedure where an error occurred.

ERROR_MESSAGE() – This function will return the complete text of the error message which cause to raise error.

Check below sample query to handle errors in stored procedure


SELECT 300/0



SELECT ErrorNumber = ERROR_NUMBER(), ErrorSeverity = ERROR_SEVERITY(), ErrorState =ERROR_STATE(),

ErrorProcedure = ERROR_PROCEDURE(), ErrorLine = ERROR_LINE(), ErrorMessage =ERROR_MESSAGE()


What is the difference between view and stored procedure in sql server?

View in SQL Server

A view represents a virtual table. By using view we can join multiple tables and present the data as coming from a single table.

For example consider we have two tables

      1)    UserInformation table with columns userid, username

      2)    SalaryInformation table with columns salid, userid, salary

Create VIEW by joining above two tables




SELECT a.userid,a.username,b.salary from UserInformation a INNER JOIN SalaryInformation b ONa.userid=b.userid


By using above view we can get username or salary based on userid for that we need to create procedure like as shown below


@uid INT



SELECT username from VW_UserInfo WHERE userid=@uid


If you observe above procedure it’s like getting username from single table (VW_UserInfo) by passing userid

Stored Procedure

A stored procedure is a group of sql statements that has been created and stored in the database. Stored procedure will accept input parameters so that a single procedure can be used over the network by several clients using different input data. Stored procedure will reduce network traffic and increase the performance. If we modify stored procedure all the clients will get the updated stored procedure

Sample of creating Stored Procedure

USE AdventureWorks2008R2;




    SELECT FirstName, LastName FROM Person.Person;


EXEC sp_who;

EXEC dbo.sp_who;


DROP PROCEDURE dbo.sp_who;


What is the difference between dispose and finalize methods in c#?

Dispose() Method

     –  This dispose method will be used to free unmanaged resources like files, database connection etc.

     –  To clear unmanaged resources we need to write code manually to raise dispose() method.

     –  This Dispose() method belongs to IDisposable interface.

     –  If we need to implement this method for any custom classes we need to inherit the class from IDisposable interface.

     –  It will not show any effect on performance of website and we can use this method whenever we want to free objects immediately.

//Implement Dispose Method.

public class TestDispose : IDisposable


private bool disposed = false;

//Implement IDisposable.

public void Dispose()




protected virtual void Dispose(bool disposing)


if (!disposed)


if (disposing)


// clean unmanged objects


// clean unmanaged objects).

disposed = true;




Finalize() Method

     –  This method also free unmanaged resources like database connections, files etc…

     –  It is automatically raised by garbage collection mechanism whenever the object goes out of scope.

     –  This method belongs to object class.

     –  We need to implement this method whenever we have unmanaged resources in our code and make sure these resources will be freed when garbage collection process done.

     –  It will show effect on performance of website and it will not suitable to free objects immediately.     


// Implementing Finalize method

public class Sample


//At runtime destructor automatically Converted to Finalize method.



// your clean up code



What is the difference between constantand readonly in c#?


  1. Const can only be initialized at the time of declaration of the field.
  2. Const values will evaluate at compile time only.
  3. Const value can’t be changed these will be same at all the time.
  4. This type of fields are required when one of the field values remains constant throughout the system like Pi will remain same in your Maths Class.


  1. The value will be initialized either declaration time or the constructor of the class allowing you to pass the value at run time.
  2. Read only values will evaluate at runtime only.

public class Const_VS_Readonly


public const int I_CONST_VALUE = 2;

public readonly int I_RO_VALUE;

public Const_VS_Readonly()





Suppose if you want the value of the constant won’t change use a const or if you have a constant that may change or when in doubt, use a readonly.  I hope it helps.