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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:00:44+00:00 2026-05-21T18:00:44+00:00

I currently have a dropdownlist which is populated via an SQLDataSource from the Module

  • 0

I currently have a dropdownlist which is populated via an SQLDataSource from the Module Table in my database.
The Module Table has 3 fields: ModuleID, ModuleName and CourseID.
Here is my code for my dropdownlist;

<asp:DropDownList ID="ModuleDropDownList" 
                        style="position:absolute; top: 35px; left: 152px;" runat="server" 
                        DataSourceID="SqlDataSource2" DataTextField="ModuleName" 
                        AutoPostBack="True" 
                        >

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:RegisterConnectionString %>" 
                        SelectCommand="SELECT DISTINCT * FROM [Module] WHERE ([CourseID] = @CourseID)">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="CourseDropDownList" Name="CourseID" 
                                PropertyName="SelectedValue" Type="Int32" />
                        </SelectParameters>

                    </asp:SqlDataSource>

When the user clicks a Save button on the page then the selected value in the dropdownlist is recorded in another database table called Attendance with a field ModuleID, however the problem I am having is to display all the ModuleName in the dropdownlist but depending on the selected ModuleName it will add the respective ModuleID to the ModuleID field in the Attendance table.
Here is my code which saves the selected value in the dropdownlist to the ModuleID field in the Attendance Table;

                command = new SqlCommand("INSERT INTO Attendance(Present, Date, StudentID, StudentName, ModuleID) VALUES (@Attendance, @Date, @StudentID, @StudentName, @ModID)", connection);
                command.Parameters.AddWithValue("@Attendance", attendance);
                command.Parameters.AddWithValue("Date", DateTime.Now);
                command.Parameters.AddWithValue("@StudentID", StudentID);
                command.Parameters.AddWithValue("@StudentName", StudentName);
                command.Parameters.AddWithValue("@ModID", ModuleDropDownList.SelectedValue);

However the ModuleID field in the Attendance table has the data type Int so I need a way of recording the ModuleID in the Attendance table based on the ModuleName chosen from the dropdownlist.
Any help is much appreciated, thanks in advance!

  • 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-21T18:00:45+00:00Added an answer on May 21, 2026 at 6:00 pm

    based on your code, I’ll set the DataValueField property on the “ModuleDropDownList” to “ModuleID”(or whatever you call it). Then you’ll get the moduleid when accessing the SelectedValue property of the dropdownlist.

    good luck

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

Sidebar

Related Questions

my dropdownlist is populated from the database as in: DataTable dt = GetData(); ddlMylist.DataSource
I have a dropdown list that is currently populated from a result set of
Scenario: I have a page which contains a dropdownlist and a table which contains
I have a Gridview in which one of the template fields has a radiobuttonlist
I have a DropDownList that is populated with the primary key of Table A.
I have a string which represents a date, its given back from a DropDownList.
I currently have the following table definition: <table border=1 cellspacing=0 bordercolor=#CEDFEF cellpadding=1> I am
I currently have a MySQL database that I am accessing using PHP. You search
I currently have: <div class=generic-block-70> <div class=generic-content-70> <table id=voteBlock> // stuff </table> </div> </div>
I have a model which has a collection of users. I'm looping through this

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.