المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Deserialize multiple list xml and bind to Datagridview



C# Programming
10-19-2013, 11:36 AM
This is my XML structure after serializing
</span span class="code-SummaryComment"version/spanspan class="code-keyword"="/spanspan class="code-keyword"1.0"/spanspan class="code-SummaryComment"?/spanspan class="code-SummaryComment"> Task ID 1 Task Desc 1 Task Person 1 Task Long 1 Task lat 1 1 Task Type 1 Task Title 1 Task Desc 1 test test2 test test2
Now I want to add all data from this xml file into my datagridview. I tried to use this code

XmlSerializer xmlser = new XmlSerializer(typeof(List)); StreamReader srdr = new StreamReader(@"D:\myfile.xml"); List p = (List)xmlser.Deserialize(srdr); srdr.Close(); dataGridView1.DataSource = p;
With my TaskModel class is

public class TaskModel{ public string TaskID { get; set; } public string TaskTitle { get; set; } public string TaskDecs { get; set; } public string TaskPerson { get; set; } public string TaskLong { get; set; } public string TaskLat { get; set; } public string TaskTime { get; set; } public List TaskQuestions { get; set; }}

And TaskQuestion.cs is

public class TaskQuestion{ public string TaskQuestionId { get; set; } public string TaskQuestionType { get; set; } public string TaskQuestionTitle { get; set; } public string TaskQuestionDesc { get; set; } public List<span class="code-keyword"string/span> TaskQuestionAnswers { get; set; } public List<span class="code-keyword"string/span> Answers { get; set; }}
If I deserialize with the above code, I just get some element of TaskModel, except TaskQuestions because it's a list. How can I get it and bind to my datagridview? I want to display the following result into dataGridView, such asTaskID | TaskTitle | Task Desc | TaskQuestionID | TaskQuestionType | TaskQuestionAnswers Please help me.