Tuesday, January 30, 2024

Finding DropDownList index by text - dropdown with foreach loop

 ddlsample.SelectedIndex = ddlsample.Items.IndexOf(ddlsample.Items.FindByValue("x")); // If you want to find text by value field.

ddlsample.SelectedIndex = ddlsample.Items.IndexOf(ddlsample.Items.FindByText("x"));// If you want to find text by TextField.




ProceedingsActiveList.ForEach(p => { p.ConductingOfficerTypeName = ddlConductingProsecutor.Items.FindByValue(p.ConductingOfficerType.Value.ToString()).Text;  });

reference:- https://stackoverflow.com/questions/5014864/finding-dropdownlist-index-by-text

No comments:

Post a Comment