1

I just wanted to bind the below List object to Grid view. That list contains another List. So when I bind the datasource, that column is coming as EMPTY.

Details below:

List<Person> Persons = new List<Person>();
public class Person
{
    public string Name1;
    public string Name2;
    public List<string> Address;
    public DateTime DateOfBirth;
    public string TeamName;
}

I assigned my gridview as below:

var data = new List<Persons>();
data = GetData();
GrdPerson.DataSource = data;
GrdPerson.DataBind();

Since we have address as List<string> in datasource, it is coming as empty in page.

I know that Address does not contain any public property hence it is coming as empty. So I tried to use Gridview in Address column of Master Grid.

But do not know how to assign the datasource at a time.

1 Answer 1

1

You can handle the gridview's RowDataBound event to DataBind the inner grid:

protected void GrdPerson_RowDataBound(Object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Person person = (Person)e.Row.DataItem;
        GridView innerGrid = (GridView)e.Row.FindControl("GrdPersonAddresses");
        innerGrid.DataSource = person.Address;
        innerGrid.DataBind();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.