Class DropDownField
Represents a dropdown field in the SfPdfViewer2 component.
Inherited Members
Namespace: Syncfusion.Blazor.SfPdfViewer
Assembly: Syncfusion.Blazor.SfPdfViewer.dll
Syntax
public class DropDownField : FormFieldInfo
Remarks
Initializes a new instance of the DropDownField class with the default field type set to "DropDown."
This field allows users to select a single option from a predefined list in interactive PDF forms.
Examples
DropDownField dropDownField = new DropDownField();
dropDownField.Name = "Options";
// Adds options to the dropdown
dropDownField.Items = new List<ListItem> {
new ListItem { Name = "Option 1", Value = "Value 1" },
new ListItem { Name = "Option 2", Value = "Value 2" },
new ListItem { Name = "Option 3", Value = "Value 3" }
};
dropDownField.SelectedIndex = 1; // Selects "Option 2" (index is 0-based)
await viewer.AddFormFieldsAsync(new List<FormFieldInfo> { dropDownField });
Constructors
DropDownField()
Initializes a new instance of the DropDownField class in the SfPdfViewer2 component.
Declaration
public DropDownField()
Remarks
This constructor creates a dropdown field with the default field type set to "DropDown."
Dropdown fields allow users to select a single option from a predefined list in interactive PDF forms.
Examples
DropDownField dropDownField = new DropDownField();
dropDownField.Name = "Options";
// Adds options to the dropdown
dropDownField.Items = new List<ListItem> {
new ListItem { Name = "Option 1", Value = "Value 1" },
new ListItem { Name = "Option 2", Value = "Value 2" },
new ListItem { Name = "Option 3", Value = "Value 3" }
};
dropDownField.SelectedIndex = 1; // Selects "Option 2" (index is 0-based)
await viewer.AddFormFieldsAsync(new List<FormFieldInfo> { dropDownField });
Properties
Items
Gets or sets the list of selectable options in the DropDownField of the SfPdfViewer2 component.
Declaration
public List<ListItem> Items { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<ListItem> | A list of ListItem containing the available options for the dropdown field. |
Remarks
The Items property holds a collection of ListItem objects,
each representing an option available in the dropdown field.
Developers can populate this list with predefined choices for users to select from.
Examples
The following example demonstrates how to add options to a dropdown field:
DropDownField dropDownField = new DropDownField();
dropDownField.Name = "Options";
// Adds options to the dropdown
dropDownField.Items = new List<ListItem> {
new ListItem { Name = "Option 1", Value = "Value 1" },
new ListItem { Name = "Option 2", Value = "Value 2" },
new ListItem { Name = "Option 3", Value = "Value 3" }
};
dropDownField.SelectedIndex = 1; // Selects "Option 2" (index is 0-based)
await viewer.AddFormFieldsAsync(new List<FormFieldInfo> { dropDownField });
SelectedIndex
Gets or sets the index of the selected item in the DropDownField of the SfPdfViewer2 component.
Declaration
public int SelectedIndex { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | An System.Int32 representing the index of the selected item. |
Remarks
The SelectedIndex property determines which option is selected in the dropdown list.
The index is zero-based, meaning the first item in the list has an index of 0
.
If set to -1
, no item is selected by default.
Examples
The following example demonstrates how to select an option in a dropdown field:
DropDownField dropDownField = new DropDownField();
dropDownField.Name = "Options";
// Adds options to the dropdown
dropDownField.Items = new List<ListItem> {
new ListItem { Name = "Option 1", Value = "Value 1" },
new ListItem { Name = "Option 2", Value = "Value 2" },
new ListItem { Name = "Option 3", Value = "Value 3" }
};
dropDownField.SelectedIndex = 1; // Selects "Option 2" (index is 0-based)
await viewer.AddFormFieldsAsync(new List<FormFieldInfo> { dropDownField });