How to add an item to a drop down list in ASP.NET?

后端 未结 3 1395
孤城傲影
孤城傲影 2021-02-01 02:18

I want to add the "Add new" at a specific index, but I am not sure of the syntax. I have the following code:

protected void Page_Load(object sender, Eve         


        
3条回答
  •  Happy的楠姐
    2021-02-01 03:18

    Which specific index? If you want 'Add New' to be first on the dropdownlist you can add it though the code like this:

    
         
    
    

    If you want to add it at a different index, maybe the last then try:

    ListItem lst = new ListItem ( "Add New" , "0" );
    
    DropDownList1.Items.Insert( DropDownList1.Items.Count-1 ,lst);
    

提交回复
热议问题