Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Dropdownlist select only first value

Dropdownlist select only first value

Scheduled Pinned Locked Moved ASP.NET
database
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    haleemasher
    wrote on last edited by
    #1

    here is my code whenever i want to change the value of my dropdownlist i select only first value it can't change to any other value. plz chk and reply

    private void bounddropdownlist()
    {
    string query = "select CouponName,CouponTypeID from CouponType";
    DAL Helper = new DAL();
    Helper.ConnectionString = ConfigurationManager.AppSettings["ConnectionString"].ToString();
    ds = new DataSet();
    ds = Helper.ExecuteDataSet(CommandType.Text, query, null);
    ddlCType.DataValueField = "CouponTypeID";
    ddlCType.DataTextField = "CouponName";
    ddlCType.DataSource = ds;
    ddlCType.DataBind();
    }

    C 1 Reply Last reply
    0
    • H haleemasher

      here is my code whenever i want to change the value of my dropdownlist i select only first value it can't change to any other value. plz chk and reply

      private void bounddropdownlist()
      {
      string query = "select CouponName,CouponTypeID from CouponType";
      DAL Helper = new DAL();
      Helper.ConnectionString = ConfigurationManager.AppSettings["ConnectionString"].ToString();
      ds = new DataSet();
      ds = Helper.ExecuteDataSet(CommandType.Text, query, null);
      ddlCType.DataValueField = "CouponTypeID";
      ddlCType.DataTextField = "CouponName";
      ddlCType.DataSource = ds;
      ddlCType.DataBind();
      }

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Well, again, your code really sucks. You need to abandon this project, and work on something more simple while you are just learning and cannot write commercial quality code. You seem to not know anything about ASP.NET and how it works yet.

      haleemasher wrote:

      ddlCType.DataBind();

      Every time you do this, the selected index is reset. I assume you call it in page load, and it therefore runs prior to your event, which is the problem.

      haleemasher wrote:

      string query = "select CouponName,CouponTypeID from CouponType"; DAL Helper = new DAL(); Helper.ConnectionString = ConfigurationManager.AppSettings["ConnectionString"].ToString(); ds = new DataSet(); ds = Helper.ExecuteDataSet(CommandType.Text, query, null);

      This is an absolute joke.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      H N 2 Replies Last reply
      0
      • C Christian Graus

        Well, again, your code really sucks. You need to abandon this project, and work on something more simple while you are just learning and cannot write commercial quality code. You seem to not know anything about ASP.NET and how it works yet.

        haleemasher wrote:

        ddlCType.DataBind();

        Every time you do this, the selected index is reset. I assume you call it in page load, and it therefore runs prior to your event, which is the problem.

        haleemasher wrote:

        string query = "select CouponName,CouponTypeID from CouponType"; DAL Helper = new DAL(); Helper.ConnectionString = ConfigurationManager.AppSettings["ConnectionString"].ToString(); ds = new DataSet(); ds = Helper.ExecuteDataSet(CommandType.Text, query, null);

        This is an absolute joke.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        H Offline
        H Offline
        haleemasher
        wrote on last edited by
        #3

        u mean i will write

        ddlCType.DataBind();

        in page load or i write all my code in pageload????

        C 1 Reply Last reply
        0
        • H haleemasher

          u mean i will write

          ddlCType.DataBind();

          in page load or i write all my code in pageload????

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          I assume this method is being called by pageload now ? What is calling it ? I am saying if you do this in page load, or any time prior to trying to access the selection, it will reset the selection. In fact, you should use IsPostback blocks to only load the data the first time, after that, it is in viewstate

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          1 Reply Last reply
          0
          • C Christian Graus

            Well, again, your code really sucks. You need to abandon this project, and work on something more simple while you are just learning and cannot write commercial quality code. You seem to not know anything about ASP.NET and how it works yet.

            haleemasher wrote:

            ddlCType.DataBind();

            Every time you do this, the selected index is reset. I assume you call it in page load, and it therefore runs prior to your event, which is the problem.

            haleemasher wrote:

            string query = "select CouponName,CouponTypeID from CouponType"; DAL Helper = new DAL(); Helper.ConnectionString = ConfigurationManager.AppSettings["ConnectionString"].ToString(); ds = new DataSet(); ds = Helper.ExecuteDataSet(CommandType.Text, query, null);

            This is an absolute joke.

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            I think DataSet and DataTable are the most misused classes in .NET framework. :)

            Navaneeth How to use google | Ask smart questions

            C 1 Reply Last reply
            0
            • N N a v a n e e t h

              I think DataSet and DataTable are the most misused classes in .NET framework. :)

              Navaneeth How to use google | Ask smart questions

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Well, for a class called DAL to require a connection string AND SQL, just beggars belief. The sad thing is, someone somewhere is paying for this code, and I am certain he will ignore what I said, and deliver a project that is poorly written, unmaintainable, and totally insecure. You have to wonder who is basing their inventory systems, staff management and other vital functions to this sort of third rate beginner code, and, worse, if the bad job being done by these people, will end up reflecting on how dumb managers view you and I, people who have done the work to learn how to write professional code, before presuming to charge money for our efforts.

              Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

              A 1 Reply Last reply
              0
              • C Christian Graus

                Well, for a class called DAL to require a connection string AND SQL, just beggars belief. The sad thing is, someone somewhere is paying for this code, and I am certain he will ignore what I said, and deliver a project that is poorly written, unmaintainable, and totally insecure. You have to wonder who is basing their inventory systems, staff management and other vital functions to this sort of third rate beginner code, and, worse, if the bad job being done by these people, will end up reflecting on how dumb managers view you and I, people who have done the work to learn how to write professional code, before presuming to charge money for our efforts.

                Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                A Offline
                A Offline
                Arun Jacob
                wrote on last edited by
                #7

                Christian Graus wrote:

                and deliver a project that is poorly written, unmaintainable, and totally insecure.

                Whatever Christian is pointed out is right but If proper code review is there it won't happen. right?

                Arun Jacob http://codepronet.blogspot.com/

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups