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. General Programming
  3. C#
  4. Clarification On Static Member [modified]

Clarification On Static Member [modified]

Scheduled Pinned Locked Moved C#
databasesysadminhelpquestion
2 Posts 2 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.
  • R Offline
    R Offline
    Rahul83
    wrote on last edited by
    #1

    Hi friends..plz go through this pseudo code I Included Requirid Namespaces Dataset ds;--------------------------------------1 //static Dataset ds;-----------------------------2 protected void page_load(parameters) { ds = function in Data acesss Layer which retrives records from database and returns dataset. populatedatagrid(); } void populatedatagrid() { if(mydropdownlist.selectedIndex=0) datagrid1.datasource=ds; else { datagrid1.Datasource= here I performed filtering action using Row Filter Property and selected Index Value } } void mydropdownlist_selectedIndexchanged(parameters) { populatedatagrid(); } I am designing a web page where by default all records will displayed.but by selecting from dropdownlist I can filter the records.Later I thought its not right to perform the fuctionalities of the page_load event at each postback(unnecessry making connection to the database)..so i used Page.Ispostback to avoid that..so first time it worked fine but when i selected from dropdwn list it throws an error "object reference not set to an instance of object".. reason for above error i understood(because in page load event i am returning dataset which does not happened at page post back)..so one of my friend commented the line no-1 and uncommented the line no-2 in above code..thus made dataset static..and it works What I am not understanding is why making the dataset static solved the task..though HTTP is static?Is making dataset ststic makes the records to be saved at server? Warm Regards, Rahul Agarwal -- modified at 7:28 Tuesday 12th June, 2007

    T 1 Reply Last reply
    0
    • R Rahul83

      Hi friends..plz go through this pseudo code I Included Requirid Namespaces Dataset ds;--------------------------------------1 //static Dataset ds;-----------------------------2 protected void page_load(parameters) { ds = function in Data acesss Layer which retrives records from database and returns dataset. populatedatagrid(); } void populatedatagrid() { if(mydropdownlist.selectedIndex=0) datagrid1.datasource=ds; else { datagrid1.Datasource= here I performed filtering action using Row Filter Property and selected Index Value } } void mydropdownlist_selectedIndexchanged(parameters) { populatedatagrid(); } I am designing a web page where by default all records will displayed.but by selecting from dropdownlist I can filter the records.Later I thought its not right to perform the fuctionalities of the page_load event at each postback(unnecessry making connection to the database)..so i used Page.Ispostback to avoid that..so first time it worked fine but when i selected from dropdwn list it throws an error "object reference not set to an instance of object".. reason for above error i understood(because in page load event i am returning dataset which does not happened at page post back)..so one of my friend commented the line no-1 and uncommented the line no-2 in above code..thus made dataset static..and it works What I am not understanding is why making the dataset static solved the task..though HTTP is static?Is making dataset ststic makes the records to be saved at server? Warm Regards, Rahul Agarwal -- modified at 7:28 Tuesday 12th June, 2007

      T Offline
      T Offline
      turbochimp
      wrote on last edited by
      #2

      First off, this is an ASP.Net question, not one specific to C#. You should post it to the ASP.Net forum for more timely response. Now, unless you personally make some attempt to persist your data source (or reconnect and query it each time) across page turns, it will not persist itself. At the very least, you need to bind your data source to its control after each page turn (Postback or not), and at most - meaning if you don't want to reload your data after each page turn - you need to persist it statefully. The static variable is a bit much for this application, but it proves the point. Is ViewState enabled for your dropdownlist? If you're doing filtering after your initial binding it won't really matter since you'll need access to your datasource, not the expression of the data in the control, but it's something to check. Other ways to do the same thing would be to push the data source to ViewState manually, or use the Session or Application objects - it all depends upon your needs. I would recommend looking up the ASP.Net page life cycle to better understand what happens each time a page is turned (whether it's a new HTTP Request or a Postback). Good luck

      The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

      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