示例#1
0
    /// <summary>
    /// The example below shows how to Select the EnrollmentId and Comments columns for use with a with a Drop Down List, Combo Box, Checked Box List, List View, List Box, etc
    /// </summary>
    private void SelectCourseEnrollmentDropDownListData()
    {
        List <CourseEnrollment> objCourseEnrollmentCol = CourseEnrollment.SelectCourseEnrollmentDropDownListData();

        // Example 1:  directly bind to a drop down list - for ASP.NET Web Forms
        // DropDownList ddl1 = new DropDownList();
        // ddl1.DataValueField = "EnrollmentId";
        // ddl1.DataTextField = "Comments";
        // ddl1.DataSource = objCourseEnrollmentCol;
        // ddl1.DataBind();

        // Example 2:  add each item through a loop - for ASP.NET Web Forms
        // DropDownList ddl2 = new DropDownList();

        // foreach (CourseEnrollment objCourseEnrollment in objCourseEnrollmentCol)
        // {
        //     ddl2.Items.Add(new ListItem(objCourseEnrollment.Comments, objCourseEnrollment.EnrollmentId.ToString()));
        // }

        // Example 3:  bind to a combo box.  for Windows Forms (WinForms)
        // ComboBox cbx1 = new ComboBox();

        // foreach (CourseEnrollment objCourseEnrollment in objCourseEnrollmentCol)
        // {
        //     cbx1.Items.Add(new ListItem(objCourseEnrollment.Comments, objCourseEnrollment.EnrollmentId.ToString()));
        // }
    }