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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:53:08+00:00 2026-06-02T03:53:08+00:00

strSQL = SELECT * FROM User_Reg WHERE User_ID=’ + UserId + ‘; DataTable dataTablerepeaterUserList

  • 0
 strSQL = "SELECT * FROM User_Reg WHERE User_ID='" + UserId + "'";
           DataTable dataTablerepeaterUserList = null;
           dataTablerepeaterUserList =objSqlDbComm.ExecuteDatasetQuery(strSQL).Tables[0];


foreach (DataRow dr in dataTablerepeaterUserList.Rows)
{   
   ddlTitle.SelectedItem.Text = dr["Title"].ToString();
}


 <asp:DropDownList ID="ddlTitle" runat="server" CssClass="csstextbox" >
      <asp:ListItem>Mr.</asp:ListItem>
      <asp:ListItem>Mrs.</asp:ListItem>
      <asp:ListItem>Miss.</asp:ListItem>
     <asp:ListItem>Dr.</asp:ListItem>
 </asp:DropDownList>

If, suppose, dr[“Title”]=Dr. Then it is overwrite Mr. with Dr. and got result like:

| Dr.  |
| Mrs. |
| Miss.|
| Dr.  |

I am passing User_ID from View_User.aspx to Create_User.aspx for edit user purpose using querystring. Id getting proper, showing all correct fields in Create_User.aspx. All controls get correct data properly. But when I populate title of current user then it overwrite with first item of DropDownList. (I have only problem with DropDownList it is overwritten).

  • 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-02T03:53:11+00:00Added an answer on June 2, 2026 at 3:53 am

    The problem with your code, is that you are just overwriting the .text property of the first ListItem in the DropDownList.

    What you want to do is find the existing ListItem that you want, and modifies the SelectedIndex property of the DropDownList so that the proper item is selected. This should work for you:

    // Find the correct list item in the drop down based on your data
    ListItem theItemYouWant = ddlTitle.Items.FindByText(dr["Title"].ToString());
    // Change the selected index to that items index
    ddlTitle.SelectedIndex = ddlTitle.Items.IndexOf(theItemYouWant);
    

    As a side note, you should not concatenate strings in your SQL, like in your example. This leaves you open to SQL Injection attacks. Instead you should use parameters, like this:

    strSQL = "SELECT * FROM User_Reg WHERE User_ID = @User_ID";
    

    And then add “@User_ID” as a parameter to wherever you’re executing your query.

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

Sidebar

Related Questions

I'm trying to run this piece of code: strSQL = SELECT * FROM ORDER_DATA
Here's my code: string strSQL = SELECT * from tMedia where SKU = '
I have two tables from two different databases. For example: Table: Articles1 - Database:
Sub GetTextFileData(strSQL As String, strFolder As String, rngTargetCell As Range) ' example: GetTextFileData SELECT
I have a query to construct Sometimes it will be strSQL = 'Select *
public DataTable ExcelToDatatable_dt1 { get { foreach (GridViewRow rowItem in GridView1.Rows) { CheckBox chk;
I am trying to import data from Access to Excel based on two parameters.
I would like to load some data from an access-database in my C#-application. But
My idea is to create some generic classes for Insert/Update/Select via a C# (3.5)
I need to help to generate column name from excel automatically. I think that:

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.