Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding a column within a generic List to GridView
    primarykey
    data
    text
    <p>I tried reading all the articles and tried the solutions as well did not work for me. </p> <p>One of the solutions i tried </p> <p><a href="https://stackoverflow.com/questions/619477/binding-generic-list-array-to-gridview">Binding Generic List Array to GridView</a>.</p> <p>The new project file that I created using your tweeked sample code is below: </p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SharePointProject2 { public class abc { public string customername { get; set; } public List&lt;def&gt; DEF { get; set; } } public class def { public string materialcode { get; set; } } </code></pre> <p>} </p> <pre><code>using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Collections.Generic; namespace SharePointProject2.testing { public partial class testingUserControl : UserControl { protected void Page_Load(object sender, EventArgs e) { List&lt;abc&gt; test1 = new List&lt;abc&gt;(); List&lt;def&gt; test2 = new List&lt;def&gt;(); test2.Add(new def() { materialcode = "something" }); test1.Add(new abc() { customername = "anything", DEF = test2 }); GridView1.DataSource = test1; GridView1.DataBind(); } } </code></pre> <p>} </p> <pre><code>&lt;%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %&gt; &lt;%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt; &lt;%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt; &lt;%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt; &lt;%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %&gt; &lt;%@ Import Namespace="Microsoft.SharePoint" %&gt; &lt;%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt; &lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="testingUserControl.ascx.cs" Inherits="SharePointProject2.testing.testingUserControl" %&gt; &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText="Charge Code"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# ((List&lt;def&gt;)(Eval("DEF")))[0].materialcode %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; </code></pre> <p></p> <p>When I compile the code above, this is the error messsage </p> <p>The type or namespace name 'def' could not be found (are you missing a using directive or an assembly reference?)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload