Pre select last record in a DropDownList C #

1

I'm assigning a list to DataSource , and in this assignment I'm concatenating the code with the company name, however, it loads the list with the first selected item. How do I make the last record load pre-selected?

My code looks like this:

    for (int i = 0; i < empresa.Count; i++)
    {
            empresa[i].ParEmpresa = empresa[i].ParCodigo + " - " + empresa[i].ParEmpresa;
    }
    ddlEmpIni.DataSource = empresa;
    ddlEmpIni.DataTextField = "ParEmpresa";
    ddlEmpIni.DataValueField = "ParCodigo";
    ddlEmpIni.DataBind();
    
asked by anonymous 03.06.2016 / 20:22

1 answer

1

Do so

    for (int i = 0; i < empresa.Count; i++)
    {
            empresa[i].ParEmpresa = empresa[i].ParCodigo + " - " + empresa[i].ParEmpresa;
    }
    ddlEmpIni.DataSource = empresa;
    ddlEmpIni.DataTextField = "ParEmpresa";
    ddlEmpIni.DataValueField = "ParCodigo";
    ddlEmpIni.DataBind();
    ddlEmpIni.SelectedValue = empresa[empresa.Count()].ParCodigo;
    
03.06.2016 / 20:29