How do you manually bind a complex object to a template control like a string in gridview?

I am struggling with data binding syntax here. For example, I have a data structure like this -

public class Course{

public string CourseName {get;set;}

public string CourseCode {get;set;}

public List<Instructor> InstructorsTeaching{get;set;}

}

public class Instructor{

public string InstructorName{get;set;}

public string InstructorCode{get;set;}

}

Now, if I want to bind this Courses list to say gridview manually, I could do

<asp:TextBox runat="server" ID="tbCourseName" Text='<%# Bind("CourseName")%>'/>

specifying for the grid editing template, but how can I bind the instructors training property to say ListBox on the same line, I can not determine the syntax, here is an example of what I tried and could not

<asp:ListBox runat="server" ID="tbInstructors" 
     DataSource='<%# Eval("InstructorsTeaching") as List<Instructor> %>'>
    <asp:ListItem Text='<%# Bind("InstructorCode")%>' 
                 Value='<%# Bind("InstructorName")%>'/>...
 <as:ListBox/>

My above code doesn't work for sure :). Ideally, I would like to do this in markup instead of code.

+3
source share
2 answers
+1

, ASP.NET 2-way databinding : .

, Eval, ASP.NET Bind (.. <% # Bind ( "Customer.FirstName" )% > ).

, , , DataSource. DataSource ListBox, Eval, DataSourceID DataSource, . kludgy, .

2- , , SqlDataSource, ObjectDataSource. , .

+3

Source: https://habr.com/ru/post/1705815/


All Articles