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. faster or better approach of filling data to dropdownlist

faster or better approach of filling data to dropdownlist

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-nethelptutorial
5 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.
  • M Offline
    M Offline
    mohd imran abdul aziz
    wrote on last edited by
    #1

    Hi all, I am using asp.net2.0 , C#. I would like to know which is the best approach(faster ) to fill dopdownlist 1. making stored procedure and filling data to dropdownlist using datareader 2. passing query and filling data to dropdownlist using datareader As I am facing problem of slowness of filling data . if you find any better approach or faster approach please guide me. database is not much heavy Method I used to fill dropdownlist is public void FillctrlList2(DropDownList ctrl, string procedurename,string fieldtext ,string fieldvalue , string conn, SqlCommand cmd, int i) { try { if (con == null) { this.openconnection(conn); this.con.Open(); // con.Open(); } if (con.State == ConnectionState.Closed) { this.openconnection(conn); con.Open(); } ctrl.Items.Clear(); ctrl.Items.Add(new ListItem("Select One", "0" )); cmd.Connection = con; cmd.CommandText = procedurename; cmd.CommandType = CommandType.StoredProcedure; rdr = cmd.ExecuteReader(); ctrl.DataSource = rdr; ctrl.DataTextField = fieldtext; ctrl.DataValueField = fieldvalue; ctrl.DataBind(); rdr.Close(); } catch (Exception ex) { throw ex; } }

    regards imran khan

    G C 2 Replies Last reply
    0
    • M mohd imran abdul aziz

      Hi all, I am using asp.net2.0 , C#. I would like to know which is the best approach(faster ) to fill dopdownlist 1. making stored procedure and filling data to dropdownlist using datareader 2. passing query and filling data to dropdownlist using datareader As I am facing problem of slowness of filling data . if you find any better approach or faster approach please guide me. database is not much heavy Method I used to fill dropdownlist is public void FillctrlList2(DropDownList ctrl, string procedurename,string fieldtext ,string fieldvalue , string conn, SqlCommand cmd, int i) { try { if (con == null) { this.openconnection(conn); this.con.Open(); // con.Open(); } if (con.State == ConnectionState.Closed) { this.openconnection(conn); con.Open(); } ctrl.Items.Clear(); ctrl.Items.Add(new ListItem("Select One", "0" )); cmd.Connection = con; cmd.CommandText = procedurename; cmd.CommandType = CommandType.StoredProcedure; rdr = cmd.ExecuteReader(); ctrl.DataSource = rdr; ctrl.DataTextField = fieldtext; ctrl.DataValueField = fieldvalue; ctrl.DataBind(); rdr.Close(); } catch (Exception ex) { throw ex; } }

      regards imran khan

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      There is nothing in that code that would make it slow in any way. You might make it slightly faster if you loop through the data reader youself instead of using data binding, but not enough to make it noticable unless you are putting thousands of items in the dropdown. If you really have that many items in a dropdown list, the problem is not the performance of the code, but that you have to rethink your user interface.

      Despite everything, the person most likely to be fooling you next is yourself.

      N 1 Reply Last reply
      0
      • M mohd imran abdul aziz

        Hi all, I am using asp.net2.0 , C#. I would like to know which is the best approach(faster ) to fill dopdownlist 1. making stored procedure and filling data to dropdownlist using datareader 2. passing query and filling data to dropdownlist using datareader As I am facing problem of slowness of filling data . if you find any better approach or faster approach please guide me. database is not much heavy Method I used to fill dropdownlist is public void FillctrlList2(DropDownList ctrl, string procedurename,string fieldtext ,string fieldvalue , string conn, SqlCommand cmd, int i) { try { if (con == null) { this.openconnection(conn); this.con.Open(); // con.Open(); } if (con.State == ConnectionState.Closed) { this.openconnection(conn); con.Open(); } ctrl.Items.Clear(); ctrl.Items.Add(new ListItem("Select One", "0" )); cmd.Connection = con; cmd.CommandText = procedurename; cmd.CommandType = CommandType.StoredProcedure; rdr = cmd.ExecuteReader(); ctrl.DataSource = rdr; ctrl.DataTextField = fieldtext; ctrl.DataValueField = fieldvalue; ctrl.DataBind(); rdr.Close(); } catch (Exception ex) { throw ex; } }

        regards imran khan

        C Offline
        C Offline
        ChrisKo 0
        wrote on last edited by
        #3

        catch (Exception ex)
        {
        throw ex;
        }

        Please change that portion to:

        catch (Exception ex)
        {
        throw;
        }

        By doing it your way, you lose the stack trace and it can be harder to debug future problems. And maybe you actually want to do something in that catch other than rethrowing the error? If not, what's the point of catching it in the first place? I know this doesn't have anything to do with your problem as I don't see anything wrong with your databinding. So unless you're binding a large set of data like Guffa mentioned, this should work fine.

        1 Reply Last reply
        0
        • G Guffa

          There is nothing in that code that would make it slow in any way. You might make it slightly faster if you loop through the data reader youself instead of using data binding, but not enough to make it noticable unless you are putting thousands of items in the dropdown. If you really have that many items in a dropdown list, the problem is not the performance of the code, but that you have to rethink your user interface.

          Despite everything, the person most likely to be fooling you next is yourself.

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

          Guffa wrote:

          You might make it slightly faster if you loop through the data reader youself instead of using data binding,

          Databinding uses the IEnumerator interface to iterate through each item. When we loop through the DataReader, I guess the same thing is happening. So how this can boost the performance ? Please correct me.

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

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

            Guffa wrote:

            You might make it slightly faster if you loop through the data reader youself instead of using data binding,

            Databinding uses the IEnumerator interface to iterate through each item. When we loop through the DataReader, I guess the same thing is happening. So how this can boost the performance ? Please correct me.

            All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            The data binding adds a bit of overhead because it can use many different kinds of data sources. You can improve on this slightly as you can write code specificly for the data source and for the data that it contains.

            Despite everything, the person most likely to be fooling you next is yourself.

            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