Skip to main content
added 194 characters in body
Source Link
Aakash Maurya
  • 8.5k
  • 5
  • 43
  • 76

From where DropDown1 came? In your code you are adding items in DropDownList4 and you are trying to access the value from DropDown1.

Your code should be like:

string selectedvalyear = Convert.ToString(DropDownList4.SelectedItem);
Label1.Text = selectedvalyear;

If you want to change the value of Lable1 from dropdown every time when you change item, then you must create a SelectedIndexChanged Event of DropDown and write above code in that event.

Solution-2:

You should write your code in :

If(!Page.IsPostBack)
{
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;
}

From where DropDown1 came? In your code you are adding items in DropDownList4 and you are trying to access the value from DropDown1.

Your code should be like:

string selectedvalyear = Convert.ToString(DropDownList4.SelectedItem);
Label1.Text = selectedvalyear;

From where DropDown1 came? In your code you are adding items in DropDownList4 and you are trying to access the value from DropDown1.

Your code should be like:

string selectedvalyear = Convert.ToString(DropDownList4.SelectedItem);
Label1.Text = selectedvalyear;

If you want to change the value of Lable1 from dropdown every time when you change item, then you must create a SelectedIndexChanged Event of DropDown and write above code in that event.

Solution-2:

You should write your code in :

If(!Page.IsPostBack)
{
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;
}
added 17 characters in body
Source Link
Aakash Maurya
  • 8.5k
  • 5
  • 43
  • 76

From where DropDown1 came? In your code you are adding items in DropDownList4 and you are trying to access the value from DropDown1.

Your code should be like:

string selectedvalyear = Convert.ToString(DropDownList4.SelectedValue;SelectedItem);
Label1.Text = selectedvalyear;

From where DropDown1 came? In your code you are adding items in DropDownList4 and you are trying to access the value from DropDown1.

Your code should be like:

string selectedvalyear = DropDownList4.SelectedValue;
Label1.Text = selectedvalyear;

From where DropDown1 came? In your code you are adding items in DropDownList4 and you are trying to access the value from DropDown1.

Your code should be like:

string selectedvalyear = Convert.ToString(DropDownList4.SelectedItem);
Label1.Text = selectedvalyear;
Post Undeleted by Aakash Maurya
Post Deleted by Aakash Maurya
Source Link
Aakash Maurya
  • 8.5k
  • 5
  • 43
  • 76

From where DropDown1 came? In your code you are adding items in DropDownList4 and you are trying to access the value from DropDown1.

Your code should be like:

string selectedvalyear = DropDownList4.SelectedValue;
Label1.Text = selectedvalyear;