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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:35:58+00:00 2026-06-17T04:35:58+00:00

I’m trying to figure out how to access and store the selection from a

  • 0

I’m trying to figure out how to access and store the selection from a dropdownlist to use in a SELECT command in the mainSQL class.

here are the specifics.

The DropDownList (on a page called Page.aspx):

    <asp:DropDownList 
    ID="selectInfo1" 
    runat="server" 
    AutoPostBack="True"
    DataTextField="Info1"
    DataValueField="Info1Key"
    DataSourceID="SqlDB" >
    </asp:DropDownList>

The function where I’m trying to access the DDL (in a seperate class file):

public List<ListInfo> getList()
{
List<ListInfo> sList = new List<ListInfo>();
ListInfo objList = null;
    //This is where I need to declare a variable called Info1Key and set it to the value of the ddl!
string queryString = "SELECT [UniqueID], [Date], [Info1], [Info2], [Info3] FROM [ReportedSales] WHERE ([Info1] = ' " + Info1Key + "') ORDER BY [Date]";
using (SqlConnection connection = new SqlConnection(sqlConString))
{
    using (SqlCommand command = new SqlCommand(queryString, connection))
    {
        command.Connection.Open();
        using (SqlDataReader dataReader = command.ExecuteReader())
        {
            while (dataReader.Read())
            {
                objList = new ListInfo();
                objList.ID = Convert.ToInt16(dataReader["UniqueID"]);
                objList.Date = Convert.ToDateTime(dataReader["Date"]);
                objList.Info1 = (dataReader["Info1"] as int?) ?? 0;
                objList.Info2 = (dataReader["Info2"] as int?) ?? 0;
                objList.Info3 = (dataReader["Info3"] as int?) ?? 0;
                sList.Add(objList);
            }
        }
    }
}
return sList;
}

This is the only function (im pretty sure) that calls the getList method–

    private void FillListActivity()
    {
        List<ListInfo> objList = new List<ListInfo>();
        objList = new mainSQL().getList();

        ReportingGV.DataSource = objList;
        ReportingGV.DataBind();
    }

NEW PROBLEM– GV is no longer changing when I change the DDL.

One way that I could fix that was change the Page_Load in Page.aspx.cs as follows:

Originally:

 protected void Page_Load(object sender, EventArgs e)
{
    if(!isPostBack)
    {
        FillSalesActivity();
    }
}

Working, but will I have problems?:

    protected void Page_Load(object sender, EventArgs e)
    {
        FillSalesActivity();
    }
  • 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-17T04:35:59+00:00Added an answer on June 17, 2026 at 4:35 am

    You don’t want your external classes to know or care anything about UI elements (such as drop down lists). They should be as UI-agnostic as possible.

    Instead, what you want to do in this case is pass the value to the function. So you’d change the function signature to something like this:

    public List<ListInfo> getList(string Info1Key)
    {
        // The code is the same, just use the Info1Key parameter that's been passed to the function.
    }
    

    And then you’d call the function like this:

    private void FillSalesActivity()
    {
        List<SalesInfo> objSalesList = new List<SalesInfo>();
        objSalesList = new mainSQL().getSalesList(selectInfo1.SelectedValue);
    
        SalesReportingGV.DataSource = objSalesList;
        SalesReportingGV.DataBind();
    }
    

    A few things to note:

    • You’ll want to include error-checking on your page to make sure there’s a value SelectedValue before bothering to call the function.
    • You should really look into SQL injection vulnerabilities, because your code has one. Never implicitly trust a value coming from the client, even if it’s from a drop down list and you think you control those. You don’t. The client can send any value they want if they choose to, and that value can contain SQL code which your function would merrily run against your database with all the permissions it needs. Look into using “parameterized queries” or, even better, an ORM framework. Something like Linq To Sql has a pretty quick setup and low learning curve and gets you a lot of functionality.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am confused How to use looping for Json response Array in another Array.

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.