title: Retrieve the values from a list to  Gridview in SharePoint Webpart?
body: <p>I have a List called <strong>Registration</strong> and the following are the columns of my list.</p>
  
  <p><strong>Column</strong>   :   <strong>Type</strong></p>
  
  <p>Employee Name : Person or Group<br>
  Manager Name  : Person or Group<br>
  Practice Name : Single line of text<br>
  Program Name  : Lookup<br>
  Status        : Choice<br>
  Prerequisite  : Multiple lines of text </p>
  
  <p>And now i created a web part which will display all these values as a grid view 
  here is the code which i have done for <strong>webpart.cs</strong></p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      gridViewManager.DataSource = GetData();
      gridViewManager.DataBind();
  }
  
  #region Try2
  DataTable GetData()
  {
      SPSite oSiteCollection = SPContext.Current.Site;
      SPWeb oWeb = oSiteCollection.OpenWeb();
      SPList oSPList = oWeb.Lists["Registration"];
      SPListItemCollection oSPListItemCollection = oSPList.Items;
      DataTable dt = new DataTable();            
      try
      {              
          dt.Columns.Add("Employee Name", typeof(String));
          dt.Columns.Add("Manager Name", typeof(String));
          dt.Columns.Add("Practice Name", typeof(String));
          dt.Columns.Add("Program Name", typeof(LookupField));
          //dt.Columns.Add("Program Name", typeof(String));
          dt.Columns.Add("Status", typeof(String));
          dt.Columns.Add("Prerequisite", typeof(String));               
          DataRow dataRow;                 
          foreach (SPListItem oSplistItem in oSPListItemCollection)
          {
              dataRow = dt.Rows.Add();
              dataRow["Employee Name"] = oSplistItem["Employee Name"].ToString();
              dataRow["Manager Name"] = oSplistItem["Manager Name"].ToString();
              dataRow["Practice Name"] = oSplistItem["Practice Name"].ToString();
              dataRow["Program Name"] = oSplistItem["Program Name"].ToString();
              dataRow["Status"] = oSplistItem["Status"].ToString();
              dataRow["Prerequisite"] = oSplistItem["Prerequisite"].ToString();
          }
          return dt;
      }
      catch (Exception ex)
      {
          System.Diagnostics.Debug.WriteLine("Managers Approval" + ex.Message.ToString());
          return dt;
      }
  
  #endregion Try2
  }
  </code></pre>
  
  <p>Here is the code for usercontrol code:</p>
  
  <pre><code>&lt;SharePoint:SPGridView runat="server" ID="gridViewManager" AutoGenerateColumns="false"&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField DataField="Employee Name" HeaderText="Employee Name" /&gt;
          &lt;asp:BoundField DataField="Manager Name" HeaderText="ManagerName" /&gt;
          &lt;asp:BoundField DataField="Practice Name" HeaderText="Practice Name" /&gt;
          &lt;asp:BoundField DataField="Program Name" HeaderText="Program Name" /&gt;
          &lt;asp:BoundField DataField="Status" HeaderText="Current Status" /&gt;
          &lt;asp:BoundField DataField="Prerequisite" HeaderText="Prerequisite" /&gt;
          &lt;asp:TemplateField HeaderText=""&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Button ID="BtnEdit" runat="server" Text="Take Action" /&gt;
                  &lt;asp:Button ID="Button1" runat="server" Text="View Details" /&gt;
              &lt;/ItemTemplate&gt;
              &lt;HeaderTemplate&gt;
              &lt;/HeaderTemplate&gt;
          &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
  &lt;/SharePoint:SPGridView&gt;
  </code></pre>
  
  <p>Now i am facing a proble with these two lines of code </p>
  
  <pre><code>dt.Columns.Add("Program Name", typeof(LookupField));
  dt.Columns.Add("Prerequisite", typeof(String)); 
  </code></pre>
  
  <p>if i don't use this then this webpart works perfectly . but i wanted to display these fields too . how can i do this ?</p>