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 8245179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:05:48+00:00 2026-06-07T22:05:48+00:00

Hi Guys i have two tables which look like this usertable RoleTable ———————– —————————

  • 0

Hi Guys i have two tables which look like this

          usertable                                 RoleTable
   -----------------------                     ---------------------------
  UserID|UserName|Pwd|RoleID                        RoleID|RoleName
    1   |Anil    |123|1                               1   |Admin

now i am showing the usertable in a table,where he has an AddNew Link ,when the admin clicks on AddNew link i will show him AddNew Page where he has some lables and textboxes to AddNew user,

Now what i want to do is in the AddNew Page i want to show All the RoleNames in a DropDown so that admin can select in which role the user has to be….and i want to retrieve the selected data

this is my model class

         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; }

}

this is my Controller

            [AcceptVerbs(HttpVerbs.Get)]
     public ActionResult AddNew()
    {

        ViewBag.Roles = new SelectList(GetRoles(),"RoleID","RoleName");           
        return View();
    }
    //
    //Geting All Roles In a GetRoles()/
    //
      public static GetRoles()
      {

        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++)
        {
            //roles.Add(new SelectListItem{.Value=i,.Text=i};                   
            var model = new ResourceModel();
            model.RoleId = Convert.ToInt16(ds.Tables[0].Rows[i]["GroupId"]);
            model.RoleName = ds.Tables[0].Rows[i]["EmplopyeeRole"].ToString();
            //roles.Value=Convert.ToString( model.RoleId);
            //roles.Text=model.RoleName;
        }
        conn.Close();
          return ds ;
      }

what i have to return in the above code

this is my AddNew Aspx Page

     <div>
    <% using (Html.BeginForm())
  { %>
  <%-- <form action="Create.aspx" method="post"></form>--%>
   <%:Html.ValidationSummary(true)%>
     <fieldset>
   <legend style="color:Orange; font-weight:bolder;">AddNew Project</legend>

    <div class="editor-label" style="color:Orange; font-weight:bolder;">
        <%: Html.LabelFor(model => model.EmployeeName)%>
    </div>
    <div class="editor-field">
       <%:Html.EditorFor(model => model.EmployeeName)%>
      <%: Html.ValidationMessageFor(model => model.EmployeeName)%>
    </div>

    <div class="editor-label" style="color:Orange; font-weight:bolder;">
       <%:Html.LabelFor(model => model.EmployeeEmailId)%>
    </div>
    <div class="editor-field">
       <%:Html.EditorFor(model => model.EmployeeEmailId)%>
       <%:Html.ValidationMessageFor(model => model.EmployeeEmailId)%>
    </div>
    <div class="editor-label" style="color:Orange; font-weight:bolder;">
    <%:Html.LabelFor(model => model.EmployeePassword)%>
    </div>
    <div class="editor-field">
    <%:Html.EditorFor(model => model.EmployeePassword)%>
    <%:Html.ValidationMessageFor(model => model.EmployeePassword)%>
    </div>
      <div class="editor-label" style="color:Orange; font-weight:bolder;">
    <%:Html.LabelFor(model => model.GroupName)%>
    </div>
    <div class="editor-field">
    <%:Html.EditorFor(model => model.GroupName)%>
    <%:Html.ValidationMessageFor(model => model.GroupName)%>
    <p>
        <input type="submit" value="Create" style="color:Orange; font-weight:bolder;"/>
    </p>
    </fieldset>
    <%} %>        
  </div>

Can any one help me in doing this please in MVC3…. i have to show the RoleNames In a DropDown I have to retreive the value selected in my [AcceptVerbs(HttpVerbs.Post)] in controller….any ideas please

i have a store Procedure for MY [AcceptVerbs(HttpVerbs.Post)] where with the selected dropdown value i will insert the RoleID of the RoleName In Db

     Create Procedure InsertEmplyoee
       (
       @EmployeeName varchar(50),
       @EmployeeEmailId varchar(50),
      @EmployeePassword varchar (50),
       @GroupName varchar (50)
          )
       as
       begin
       insert into EmployeeDetails   (EmployeeName,EmployeeEmailId,EmployeePassword,GroupId) values 
    (@EmployeeName,@EmployeeEmailId,@EmployeePassword,(select GroupId from   EmployeeGroup where EmplopyeeRole=@GroupName ))

end
go

  • 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-07T22:05:50+00:00Added an answer on June 7, 2026 at 10:05 pm

    Make your Get Action Like this:

    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult AddNew()
    {
            ViewBag.RoleId = new SelectList(GetRoles(), "RoleID", "RoleName");
            return View();
    }
    

    GetRoles should return a list of Role

    In your view:

    @Html.DropDownList("RoleId")
    

    Edit: Explanation

    Html.DropDownList method will search ViewBag (ViewData actually) for a List of SelectListItem with name RoleId and create the DropDown list with that. You need not explicitly specify the list yourself.

    Edit: Correcting GetRoles

    GetRoles method should be like this:

    public static List<Role> GetRoles() {
        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);
    
        List<Role> allRoles = new List<Role>();
        for(int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) {
            Role role = new Role {
                RoleId = Convert.ToInt16(ds.Tables[0].Rows[i]["GroupId"]),
                RoleName = ds.Tables[0].Rows[i]["EmplopyeeRole"].ToString()
            };
    
            allRoles.Add(role);
        }
        conn.Close();
        return allRoles;
    }
    

    I have always worked with EntityFramework. Why don’t you go with that or some other ORM?

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

Sidebar

Related Questions

guys i have arrays in which i have to match this kind of text
Guys, I have two basic tables ( id , first_name ). I want to
If i have SQL Server tables like this: Location ---------- LocationId int PK Field1
Ok guys, so I'm making a scheduler. So I have two tables so far,
Hi Guys I have two tables table B has a many to 1 relationship
Hi guys currently i have this code. I would like to add another field
guys I have two question to ask, they're easy, but bothering me for a
hi guys i have two pipe delimited files,first file contains 1000 records and second
Hi guys i have my array below and i want to retrieve two rows:as
guys, I wrote a function to test if two inputs (a and b) have

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.