Set a dropdown list item as selected dynamically using ASP .NET VB / C#

To set a dropdown list item as selected dynamically using ASP .NET VB / C# write following code on Page_Load event

VB Code:

dropdownlist.ClearSelection()

dropdownlist.Items.FindByValue(value).Selected = True


C# Code:

dropdownlist.ClearSelection();

dropdownlist.Items.FindByValue(value).Selected = True;


Description:

First line of code is to clear the selection if you have already selected item true, otherwise you would get error.

In Second line you can use your variable against value to select dropdown list item dynamically.

Comments

Popular posts from this blog

Global Mining and Trade of Nephrite Jade