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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:57:50+00:00 2026-05-19T01:57:50+00:00

I have a WebForm before_adm.aspx.cs which has the code as follows: . . .

  • 0

I have a WebForm before_adm.aspx.cs which has the code as follows:

.
.
.
public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
          DropDown abs =new DropDown();
          abs.DropDown();
    }
.....

I want to call a function DropDown() which is in file DropDown.cs The code in DropDown.cs is as follows:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Odbc;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;

/// <summary>
/// Summary description for DropDown
/// </summary>
public class DropDown
{
    public DropDown()
    {
        try
        {

            OdbcConnection myConn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=10.155.160.130;Database=testcase;User=root;Password=;Option=3;");
            OdbcCommand myCmd = new OdbcCommand("select skey,casecode from casetype", myConn);
            myConn.Open();
            OdbcDataReader myReader = myCmd.ExecuteReader();

            //Set up the data binding.
            DropDownList3.DataSource = myReader;
            DropDownList3.DataTextField = "skey";
            DropDownList3.DataValueField = "casecode";
            DropDownList3.DataBind();
            DropDownList3.Items.Insert(0, "<-- Select -->");

        }
        catch (Exception ex)
        {
            Response.Write(ex.StackTrace);
        }

        if (DropDownList2.SelectedItem.Text == "Register")
        {
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("STA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("STM"));
        }
        else if (DropDownList2.SelectedItem.Text == "Stamp")
        {
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("WP"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("FA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("LPA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("SA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CP"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CAPL"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("MCA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("XFER"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("ARP"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("TXA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRIR"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("WPCR"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AO"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AUA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CONP"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("ELEP"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("COAP"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("COA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("ARA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CREF"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("ITA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AAR"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("XFA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("TACR"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("EXAP"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("COP"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AUE"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AUW"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRMA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CAREV"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CONF"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("PILWP"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("SMWP"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("XOB"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("SMCP"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AELEP"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("RUIT"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CS"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("RUCA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRIA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CUSA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("EXA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("SMCRC"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("EA"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRMAB"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRMAM"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("COAPM"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CPM"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("MCAM"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AS"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("PILSM"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("CRREF"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("SMCR"));
            DropDownList3.Items.Remove(DropDownList3.Items.FindByText("AUSFC"));

        }
        else if (DropDownList2.SelectedItem.Text == "<-- Select -->")
        {
            DropDownList3.Items.Clear();
        }
    }

}

Whatever i have done till now,is it correct? I am now getting the error as:

The name 'DropDownList2' does not exist in the current context
The name 'DropDownList3' does not exist in the current context  
The name 'Response' does not exist in the current context

I want to create this function because i will be creating many such WebForms and i want to call the same function on

DropDownList2_SelectedIndexChanged
What parameters do i need to pass. i want to know the way to pass the parameters. Please guide me. i want to create many such functions in .cs file which will have many other user controls.

  • 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-19T01:57:50+00:00Added an answer on May 19, 2026 at 1:57 am

    Try this way

    public class DropDown
    {
        DropDownList dropDownList3 = null;
        DropDownList dropDownList2 = null;
    
        public DropDown()
        {
        }
    
        public void Register(DropDownList dropDown2, DropDownList dropDown3)
        {
            this.dropDownList2 = dropDown2;
            this.dropDownList3 = dropDown3;
            // your code goes here
         }
    }
    

    Use HttpContext.Current.Response.Write

    Use this class as

    DropDown abs = new DropDown();
    abs.Register(dropdown1, dropdown2);
    

    Try not to write code in constructor which might throw exception

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

Sidebar

Related Questions

I have the following webform: <%@ Page Language=C# AutoEventWireup=true CodeBehind=Default.aspx.cs Inherits=TestWebApp.Default %> <!DOCTYPE html
On my C# asp.net webform I have a search page that has roughly 20
I have a .NET webform that has a file upload control that is tied
We have a pretty big ASP.NET WebForm (web application) project with a lot of
I have a web form that has multiple ListBoxes, TextBoxes, DropDowns. If I put
Within an ASP.NET AJAX UpdatePanel on my page I have a submit button which
I have a simple webform that will allow unauthenticated users to input their information,
I have a web form that binds a DataGrid to a, normally, different data
I have a web form that I am attempting to implement dynamic drop down
Say you have a web form with some fields that you want to validate

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.