Ho il seguente codiceCome aggiungere un elemento a un elenco a discesa in asp.net
protected void Page_Load(object sender, EventArgs e)
{
DRPFill();
if (!IsPostBack)
{
DropDownList1.Items.Add("Add New");
}
}
public void DRPFill()
{
if (!IsPostBack)
{
//Object
AddMajor objMajor = new AddMajor();
//Data Table
DataTable dtMajor = objMajor.find();
//Data Source
DropDownList1.DataSource = dtMajor;
DropDownList1.DataValueField = "MajorID";
DropDownList1.DataTextField = "MajorName";
//Data Bind
DropDownList1.DataBind();
}
}
voglio aggiungere "Add new" in un indice specifico
ma non sono sicuro della sintassi
DropDownList1.Items.Insert? –
Perché il controllo nel metodo 'DRPFill'? , perché non metterlo in "if" della pagina caricata – V4Vendetta