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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:44:18+00:00 2026-05-26T20:44:18+00:00

I’m very new to asp.net and c# I would like to get some help

  • 0

I’m very new to asp.net and c# I would like to get some help with dropdownlist. I want to return the ClassName value for a specific student from the Students table in a drop down list. I also want the drop down list to be populated with all the ClassNames from the StudentClasses table. But my code behind does return any values in the drop down list.

Can someone tell me what I’ve done wrong?

I have a table called StudentClasses with the following data, e.g.:

ClassID        ClassName
==
1              5B 
2              6C
3              K/1F

I have another table called Students where the ClassID from StudentClasses is a Foreign Key, e.g.:

StudentID      FirstName  LastName   ClassID
==
1              John       Smith      1
2              Sarah      Jones      2
3              Billy      Cain       2

I want to return on my page view the following:

Class will be a drop down list of all className from StudentClasses and show John Smith’s Class, 5B.
First Name and Last Name are textboxes.
I also have an Update button so I can edit the details as well
To edit Class, they can only choose from the drop down list.

First Name: John    Last Name: Smith      Class: 5B

This is the code behind by aspx page.

protected void rptStudents_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    DropDownList ddlClassName = (DropDownList)e.Item.FindControl("ddlClassName");

    ddlClassName.DataTextField = "ClassName";
    ddlClassName.DataValueField = "ClassID";

    //this is the object that is bound to this particular item (row)
    StudentClass className = (StudentClass)e.Item.DataItem;

    //TO DO: student should contain class id instead of name.
    ddlClassName.SelectedValue = (className.ClassID).ToString();

    //to do get list of class items here and set datasource and then databind();

    Result<List<StudentClass>> result = StudentClassController.GetAllStudentClasses();
    ddlClassName.DataSource = result.Data;
    ddlClassName.DataBind();
}
  • 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-05-26T20:44:19+00:00Added an answer on May 26, 2026 at 8:44 pm

    Make sure that your control is set to AutoPostBack=true and that on Page_Load() you aren’t calling anything that would erase or overwrite the contents of the dropdown list. Specifically, I always always always screw this up myself by doing stuff like

    protected void Page_Load(object sender, EventArgs e)
    {
        PopulateDropDownList();
    }
    

    but really you need to say

    protected void Page_Load(object sender, EventArgs e)
    {
       if (!IsPostBack)
       {
          PopulateDropDownList();
       }
    }
    

    I’m having a little trouble following your code without knowing the class structure and stuff, but here’s a snippet of code that I use in our application to populate a drop down list with a text and a value:

        EmployeeList allemployees = EmployeeManager.GetList();
    
        EmployeeEDropDownList.Items.Clear();
        EmployeeEDropDownList.Items.Add("");  //add a blank item on top to simulate no selection
        foreach (Employee currentemp in allemployees)
        {
            EmployeeEDropDownList.Items.Add(new ListItem(currentemp.Name.FullNameE, currentemp.EmployeeID.ToString()));
        }
    

    Maybe that will give you an alternate idea. In my opinion this is a little bit “simpler” and easier to understand than what you have, but like I said, without seeing your entire application, I can’t really make that judgment 🙂

    Hope this helps.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I would like to count the length of a string with PHP. The string
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.