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

  • SEARCH
  • Home
  • 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 8237825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:35:57+00:00 2026-06-07T19:35:57+00:00

I want to bind Data from DB to DropDownList ,i had tried the following

  • 0

I want to bind Data from DB to DropDownList ,i had tried the following method but the data is not binded to the dropdown can any one tell where am i doing wrong

this is my controller

         [AcceptVerbs(HttpVerbs.Get)]
         public ActionResult AddNew()
          {
        ViewBag.RoleName = new SelectList(GetRoles(), "RoleID", "RoleName");
        return View();
        }
        public List<SelectListItem> GetRoles()
       {
        var roles = new List<SelectListItem>();
        SqlConnection conn = new SqlConnection("Data Source=LMIT-0039;Initial Catalog=BugTracker;Integrated Security=True");
        SqlCommand Cmd = new SqlCommand("Select GroupId,EmplopyeeRole from  EmployeeGroup", conn);
        conn.Open();
        SqlDataAdapter da = new SqlDataAdapter(Cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);         
            for (int i = 0; i <= ds.Tables[0].Rows.Count-1; i++)
            {
                var model = new ResourceModel();
                model.RoleId = Convert.ToInt16(ds.Tables[0].Rows[i]["GroupId"]);
                model.RoleName = ds.Tables[0].Rows[i]["EmplopyeeRole"].ToString();
            }          
        conn.Close();
        return roles;
    }

this is my model

              public class ResourceModel
{
    public static List<ResourceModel> GetList { get; set; }
    public Int16 EmployeeId { get; set; }
    public string EmployeeName { get; set; }
    public string EmployeeEmailId { get; set;}
    public string GroupName { get; set; }
    public string EmployeePassword { get; set; }

    public static List<SelectListItem> GetRoles { get; set; }
    public int RoleId { get; set; }
    public string RoleName { get; set; }      

}

this is my aspxPage

    <%:Html.DropDownList("RoleName")%>

when i put a breakpoint and see that i have the data in GetRoles Method..can any one tell me where am i doing wrong

  • 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-07T19:36:00+00:00Added an answer on June 7, 2026 at 7:36 pm

    I guess the problem is you have a property in the model with the name RoleName and also you have it in the ViewBag.

    So when you use <%:Html.DropDownList("RoleName")%> there is a kind of confusion.

    I would suggest change ViewBag.RoleName into something like ViewBag.Roles and then try,

    <%:Html.DropDownList("Roles")%>

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

Sidebar

Related Questions

I want to bind data from an xml file? how can I do that
I want to bind dropdown list in a gridview with datasiursce coming from data
I want to bind the data of the listbox from the two lists collection,
I want to bind some data gotten from a web service to a custom
I want to bind the data from my XML file to my userControl. So
I want to bind one data to several controls. Is there some logical control
I have a repeater bind by the data coming from database. Now on click
I have this code I want to bind data to grid view without using
I want to bind some extra data with a view. I am using tag
I'm using LINQ to query data from database and then bind it to a

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.