user175084 user175084 - 1 month ago 9
ASP.NET (C#) Question

display a particular number from dropdownlist

Is there a way in dropdownlist to show the desired number on pageload?

I have a dropdownlist control

I am using a for loop to populate it

for (int i = 1; i <= 100; i++)

Now this displays 1 on page load ... but I want to display 7..
How do I do that?


If you mean that it is the default selected value, you would just need to set a default selected value in the page load, after the list has been populated. Make sure only to do this when it is not a postback or you will overwrite any user selections.

protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)
        DropDownList1.SelectedValue = "7"