I have a choice column in my SharePoint list called Njësia
, I have created a dropdown in my solution and I want to retrieve selected value from dropdown list.
I have a label called Label1
and I want to represent the selected item in dropdown list.
I have the following code:
SPFieldChoice YearChoice = (SPFieldChoice)sampleList.Fields["Njësia"];
for (int i = 0; i < YearChoice.Choices.Count; i++)
{
DropDownList4.Items.Add(YearChoice.Choices[i].ToString());
}
string selectedvalyear = DropDownList4.SelectedValue;
Label1.Text = selectedvalyear;
I also tried this line:
string selectedvalyear = DropDownList4.Text;
The result of Label1
is null or it displays only the first item in dropdown I have enable autopostback but nothing happens Please help me!