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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:10:28+00:00 2026-05-24T11:10:28+00:00

I created an asp.net application that fills a table with information from a database,

  • 0

I created an asp.net application that fills a table with information from a database, choose a value in a drop down list and update the database. For some reason now when I go to the next date and all of the information displays correctly, but the value in the drop down list does not. Because of this, say the first page has 3 rows and the second page has 10. The first 3 rows on the second page will have the same value in the drop down list as the previous page, everything else is changed though. Here is the code used for creating the drop down list on every row:

    tc = new TableCell();
                    tc.BorderWidth = 1;
                    String rteNum = reader.GetValue(fCount - 1).ToString().TrimStart('R');

                    //this output displays the correct value
                    System.Diagnostics.Trace.WriteLine(rteNum.Trim());

                    ddl = new DropDownList();
                    ddl.ID = "route" + index;
                    ddl.Attributes["runat"] = "server";
                    ddl.Attributes["onblur"] = "refresh()";

                    ListItem item;
                    for (int i = 1; i <= 32; i++)
                    {
                        item = new ListItem();
                        item.Text = i.ToString();
                        item.Value = i.ToString();
                        if (i.ToString().Equals(rteNum.Trim()))
                        {
                            item.Selected = true;
                        }
                        ddl.Items.Add(item);

                    }
                    list.Add(ddl);

                    tc.Controls.Add(ddl);               
                    tc.ID = "tblr" + index;
                    tr.Cells.Add(tc);

                    tbl1.Rows.Add(tr);

EDIT:

The problem is I need to use the changed values if the user presses a button, however when the data is changed the information has to be dropped. So basically I need to display the information with a drop down list then update the database.

  • 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-24T11:10:29+00:00Added an answer on May 24, 2026 at 11:10 am

    One way is to do it in mark-up like this:

    <asp:DropDownList ID="ddl_1" runat="server" AutoPostBack="True" 
       DataSourceID="ds_1" DataTextField="myText" 
       DataValueField="myValue" />
    
       <asp:SqlDataSource ID="ds_1" runat="server" 
          ConnectionString="<%$ ConnectionStrings:myConnection %>" 
          <!--this is if you use a stored procedure-->
          SelectCommand="dbo.myProcedure" SelectCommandType="StoredProcedure">
          <!--this is if you use direct sql (less secure -- be careful with parameters)-->
          SelectCommand="SELECT field1 as myValue, field2 as myText FROM myTable">
       </asp:SqlDataSource>
    

    So when you want to set the selected value based on a database value (in response to a button-click, etc., you might use a sub like this in your code-behind:

    Private Sub SELECT_whatever()
            Dim myCommand As New SqlCommand("dbo.SELECT_whatever", myConnection)
            With myCommand
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .Clear()
                    .AddWithValue("myParameter", me.txtwhateverfield.text)
                End With
            End With
            Try
                myConnection.Open()
                myReader = myCommand.ExecuteReader
                While myReader.Read
                    If Not IsDBNull(myReader("field1")) Then
                        Me.ddl_instructor.SelectedValue = myReader("field1")
                    End If
                    Me.lbl_RecordID.Text = "Record ID: " & myReader("recordID")
                   -- etc. -- for all of the textboxes, labels, etc. on your page
                End While
            Catch ex As Exception
                Response.Write(ex.Message)
            Finally
                myConnection.Close()
            End Try
    

    As an alternative to using a datasoruce control in mark-up, you can use the sub above, but instead…

    1. create a data set
    2. create a data adapter
    3. call .fill on the data adapter for a table in the data set
    4. set the dropdown list’s data source to the data table
    5. call .databind() on the dropdown list.

    Here’s an example: http://support.microsoft.com/kb/306574 (CTRL+F for “databind” — it’s down in item 4)

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

Sidebar

Related Questions

I am working on an ASP.Net web application that must print dynamically created labels
We have created a web application, using ASP.NET, that allows users to upload documents
I have a pretty big web application that I created last year using ASP.NET
I use VS 2010 Ultimate. I created an 'asp.net web application' from scratch, added
I've created an ASP.NET MVC application that has an initializer attached to the PreApplicationStartMethodAttribute
I create new ASP.NET web application that use SMTP to send message. The problem
I created a GridView in an ASP.NET application and used the Auto Format tool
I have created a Web Application in asp.net 2.0. which is working fine on
I have an ASP.NET application that relies on the Random class to generate a
I created an data driven ASP.NET MVC Application locally and it works fine. Within

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.