Jan 05, 2010, 8:06 PM
Binding Store to Nest DataClass
Hello! I am trying to bind a nested DataClass to a store and having trouble with it. Basically, I have a class whose attributes are another class. This seems to be a problem because the DataReader only recognizes simple types (int, floating, date, and text) and doesn't seem to know how to handle other class.
Is it possible to setup the store to properly parse the dataclass?
Here's a simplified code:
Class definitions in DataClasses.cs:
Now the aspx code would look something like:
Any help would be appreciated! Thanks!
Is it possible to setup the store to properly parse the dataclass?
Here's a simplified code:
Class definitions in DataClasses.cs:
public class Teacher
{
public string FirstName;
public string LastName;
public string TeacherID;
public override ToString()
{
return LastName + ', ' + FirstName;
}
}
public class Course
{
public string CourseName;
public int Course ID;
public Teacher CourseTeacher;
}
public void Load_Data (object sender, StoreRefreshDataEventArgs e)
{
Course newData = new Course("John", "Doe", "1111");
storeCourse.DataSource = newData;
storeCourse.DataBind();
}
So we have a class Course, which contains Teacher class. I want to be able to load/save the Course with Teacher class included as an object in the store, while having the form display the Teacher's name.Now the aspx code would look something like:
<ext:store runat="server" ID="storeClass" AutoLoad="true" AutoDataBind="false" onRefreshData="Load_Data">
<Proxy>
<ext:DataSourceProxy/>
</Proxy>
<Reader>
<ext:JsonReader runat="server" ReaderID="CourseID">
<Fields>
<ext:RecordFields Name="CourseName"/>
<ext:RecordFields Name="CourseID"/>
<ext:RecordFields Name="CourseTeacher"/>
</Fields>
</ext:JsonReader>
</Reader>
</ext:store>
<ext:Panel runat="server" ID="MainPanel">
<Body>
<ext:FormLayOut runat="server" StoreID="storeCourse" ID="CourseForm" AutoLoad="True">
<ext:Anchor><ext:TextField runat="server" FieldLabel="Course Name" DataIndex="CourseName" ID="TxtCourseName"/></ext:Anchor>
<ext:Anchor><ext:TextField runat="server" FieldLabel="Course ID" DataIndex="CourseID" ID="TxtCourseID"/></ext:Anchor>
<ext:Anchor><ext:TextField runat="server"
FieldLabel="Teacher" DataIndex="CourseTeacher" ID="TxtCourseTeacher"/></ext:Anchor>
</ext:FormLayOut>
</Body>
</ext:Panel>
So.. is there a way to configure either form or store to view a string representation of the Teacher's name on the form display, while keeping the Teacher Class as an attribute of Course within store?Any help would be appreciated! Thanks!