protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
conOOC.Open();
SqlDataAdapter adptDDL = new SqlDataAdapter("SELECT ProgrammeCode, StaffID FROM Programme, Staff", conOOC);
DataTable dtDDL = new DataTable();
adptDDL.Fill(dtDDL);
ddlProgramme.DataSource = dtDDL;
ddlProgramme.DataTextField = "ProgrammeCode";
ddlProgramme.DataValueField = "ProgrammeCode";
ddlProgramme.DataBind();
ddlStaff.DataSource = dtDDL;
ddlStaff.DataTextField = "StaffID";
ddlStaff.DataValueField = "StaffID";
ddlStaff.DataBind();
conOOC.Close();
if (ddlProgramme.Items.Count <= 0)
{
Response.Write("<script language=javascript>alert('Please Add Some Programme');window.open('Course Maintenance.aspx','_self');</script>");
}
if (ddlStaff.Items.Count <= 0)
{
Response.Write("<script language=javascript>alert('Please Add Some Staff');window.open('Course Maintenance.aspx','_self');</script>");
}
if (ddlProgramme.Items.Count <= 0 || ddlStaff.Items.Count <= 0)
{
Response.Write("<script language=javascript>alert('Please Add Some Programme And Staff');window.open('Course Maintenance.aspx','_self');</script>");
}
}
}
it always go to if(ddlProgramme.Items.Count <= 0) condition, but i already added some data into programme table. why? :/