user1865552
user1865552

Reputation:

Bind the data to the gridview

I populate my list from database like this.

List<BObj_person> list = new List<BObj_person>();

BObj_person person = new BObj_person
                    {
                        PersonName = "aaa",
                        PersonSurname = "bbbb",
                        departman = new BObj_departman { DepartmanName = "ccc" }
                    };

list = list.Add(person);

PersonName and PersonSurname are ok, it is shown inside grid but departmanName is a problem?? how can I bind this list to datagridview like this; gridview.DataSource = list;

**I am using Ext.Net grid thank you .

Upvotes: 1

Views: 319

Answers (4)

Daniil Veriga
Daniil Veriga

Reputation: 1851

You can use ServerMapping for a ModelField.

<ext:ModelField Name="departmanName" ServerMapping="departman.Name;" />

<ext:Column runat="server" DataIndex="departmanName" />

Here is a full example of using ServerMapping.

Upvotes: 2

Damith
Damith

Reputation: 63095

set DataSource of the gridview with the collection and then

<asp:TemplateField>
    <itemtemplate>
        <p><%#DataBinder.Eval(Container.DataItem, "departman.DepartmanName")%></p>
    </itemtemplate>
</asp:TemplateField>

Upvotes: 1

Claudio Redi
Claudio Redi

Reputation: 68440

This should work, but I might be misunderstanding your question

<%# Eval("departman.DepartmanName") %>

If you're trying to simplify binding you could add a read-only property to BObj_person named DepartmanName

public class BObj_person
{
    ...
    public string DepartmanName 
    { 
       get { return departman.Name; }
    }          
}    

Upvotes: 1

Edmund Covington
Edmund Covington

Reputation: 521

You should use gridview.ItemsSource. This should be enough to get it working.

Upvotes: 0

Related Questions