In moss 2007 we use the ListView WebPart to display the List item but in Sharepoint 2010 we explore the XsltListView WebPart to display the List item.
using (SPSite site = new SPSite(SPContext.Current.Web.Url.ToString()))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Tracker"];
XsltListViewWebPart XsltListViewWebPart1 = new XsltListViewWebPart();
XsltListViewWebPart1.ListId = list.ID;
SPView lstview = list.DefaultView;
XsltListViewWebPart1.Toolbar = "";
StringBuilder xml = new StringBuilder();
xml.Append("<View Name='{" + list.DefaultView.ID.ToString("B").ToString().ToUpperInvariant() + "}' TabularView='FALSE' MobileView='TRUE' Type='HTML' Hidden='TRUE' DisplayName='' Url='" + Request.Url.ToString() + "' Level='1' BaseViewID='1' ContentTypeID='0x' ImageUrl='/_layouts/images/generic.png'>");
xml.Append("<Query><OrderBy><FieldRef Name='ID'/></OrderBy></Query>");
xml.Append("<ViewFields> <FieldRef Name='LinkTitle'/><FieldRef Name='Edit'/><FieldRef Name='Role'/></ViewFields>");

Join the conversation! Your thoughts help the community grow.