Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7890907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:28:44+00:00 2026-06-03T06:28:44+00:00

So, here is the Html helper I’ve used : @Html.DropDownList(FK_gestCompte, User.Identity.Name) this gives this

  • 0

So, here is the Html helper I’ve used :

        @Html.DropDownList("FK_gestCompte", User.Identity.Name)

this gives this html result :

 <select id="FK_gestCompte" name="FK_gestCompte"><option value="">user3</option>
 <option value="1">user1</option>
 <option value="2">admin</option>
 <option value="3">user2</option>
 <option value="5">user3</option>
 </select>

I don’t get how I can set the first line like this :

 <select id="FK_gestCompte" name="FK_gestCompte"><option value="5">user3</option>

The selectlist I’ve made has been created like that inside the controller :

        ViewBag.FK_gestCompte = New SelectList(db.my_aspnet_users, "id", "Name")

any idea?


Here is the solution given byParv Sharma :

controller :

        Dim ident As Integer = (From a In db.my_aspnet_users
                             Where a.name = User.Identity.Name
                             Select a.id).FirstOrDefault()
        ViewBag.FK_gestCompte = New SelectList(db.my_aspnet_users, "id", "Name", ident)

view :

        @Html.DropDownList("FK_gestCompte")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:28:45+00:00Added an answer on June 3, 2026 at 6:28 am

    going by the signature of the method you are using

      @Html.DropDownList("FK_gestCompte", User.Identity.Name)
    

    im assuing that User.Identity.Name is an ienumerable of SelectListItem
    so when you are filling this collection you can set any item as selected item using the Selected property of that item.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here in this html i need to get the image name arrow_down using jquery
Here is my HTML: <tr> <td colspan=2 class=borderBottomCell> <div class=benefitInfo style=WIDTH: 99%! important;> <asp:DropDownList
Here's my HTML. Apologies for formatting - this is my first-ever question! <div id=Template>
I have an HTML helper that I need to pass an Object to. This
Have a question about the design/usage of asp.net mvc here. In the html helper
Recently I posted a question about the html helper dropdownlist and got it working
so here it goes: I have a html helper which renders ActionLink s with
I'm pulling my hair out here. I'm using the DropDownListFor HTML helper in MVC3
I'm trying to port the old HTML.Image helper, that I'm sure everyone has used
When I try to bind in an MVC 3 view (using an @Html.DropDownList helper)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.