Know and use the size of the drop-down list

Hi,
I want to know the size of my drop-down list, if the size is larger than 1, i delete the item select.

public void Ecrase(object sender, EventArgs e){
int taille = (DEMANDE_STATUT.Count);
if(taille>1){
DEMANDE_STATUT.Items.Remove(DEMANDE_STATUT.SelectedValue); }
}
I used Int32.Parse - (Int) - Convert.Int32 … to convert the object to an integer
Count does not function. here is the error message :slight_smile:
Cannot convert method group ‘Count’ to non-delegate type ‘int’. Did you intend to invoke the method?
Best regards,
Abdel

Hi,

Try DEMANDE_STATUT.Count().

Kindly open a ticket in our helpdesk system for further assistance.

Best Regards,
Eddy.

Hi Eddy,
Thank you for your reply,
I have already tried "Count " without success.
Regarding Helpdesk I tried to access this link “https://helpdesk.workflowgen.com/wfgen/app_themes/default/portal/banner/bannerhd6d.htm” “Error 404”
Best Regards,
Abdel

Hi Abdel,

The error says “Cannot convert method group ‘Count’ to non-delegate type ‘int’. Did you intend to invoke the method?”

To invoke a method, you need to add parentheses at the end. Instead of Count, use Count().
You can also try .Length.

Best Regards,
Eddy.

Hi Eddy,
I tried several functions with and without parentheses, Size, Length Count… without success
For Length()


For Count()
Best Regards,
Abdel

Hi Abdel,

If DEMANDE_STATUT is a dropdownlist object then you have to use the Items parameter.
DEMANDE_STATUT.Items.Count

https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist(v=vs.110).aspx

Best Regards,
Eddy.

1 Like

Hi Eddy,
Yes, it works well, thank you very much.

Best Regards,
Abdel