protected void dgProgramme_ItemDataBound(object source, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { ((Button)e.Item.FindControl("btnDeleteProgramme")).Attributes.Add("onClick", "return confirmDeleteProgramme(this);"); ((WebControl)e.Item.Cells[3].Controls[0]).CssClass = "btn btn-warning"; } if (e.Item.ItemType == ListItemType.EditItem) { ((WebControl)e.Item.Cells[3].Controls[0]).CssClass = "btn btn-warning"; ((WebControl)e.Item.Cells[3].Controls[2]).CssClass = "btn btn-secondary"; } if (e.Item.ItemType == ListItemType.Footer) { Programme programme = new Programme(); ArrayList facultyList = programme.SelectFacultyID("", ""); DropDownList dddl = (e.Item.FindControl("ddlFacultyNameNew") as DropDownList); dddl.DataSource = facultyList; dddl.DataTextField = "Value"; dddl.DataValueField = "Key"; dddl.DataBind(); } else if (e.Item.ItemType == ListItemType.EditItem) { Programme programme = new Programme(); ArrayList facultyList = programme.SelectFacultyID("", ""); DropDownList dddl = (e.Item.FindControl("ddlFacultyName") as DropDownList); Label FacultyName = (Label)e.Item.Cells[1].FindControl("lblFacultyNameEdit"); dddl.DataSource = facultyList; dddl.DataTextField = "Value"; dddl.DataValueField = "Key"; dddl.DataBind(); dddl.SelectedIndex = dddl.Items.IndexOf(dddl.Items.FindByText(FacultyName.Text)); } }