יום רביעי, 11 בספטמבר 2013

הזרקה של enum לרשימה נגללת (DropDownList)

קודם נבנה את המחלקה, נוסיף מחלקה בפרוייקט:
 
public class enumLessonType
{
       public enumLessonType()    {}
    public enum lessonType
    {
        שהייה,
        עזר
    }
}
 
זהו, נוסיף את הפקד בדף:
<asp:DropDownList ID="DDLtypeLesson" runat="server"></asp:DropDownList>
 
ועכשיו את הפקודה שרצה על כל המחלקה, ומצרפת את כל האלמנטים:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
enumLessonType type = new enumLessonType();
DDLtypeLesson.DataSource = Enum.GetNames(typeof(enumLessonType.lessonType));
DDLtypeLesson.DataBind();
}
}
 

אין תגובות:

הוסף רשומת תגובה