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. asp.net state management issue help req'd

asp.net state management issue help req'd

Scheduled Pinned Locked Moved ASP.NET
helpcsharpcssasp-netdatabase
4 Posts 3 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
    haseeb_saeed
    wrote on last edited by
    #1

    Hi, I have a gridview (source is a list) which contains information that would be required to pull out more data from the database. actually, i wil be using that list when a btn is clicked to retrieve more information and then assign this second list to the gridview... ie 1 grid and two sources but source 2 is dependent on source1. i am using asp.net so with button click , state is lost and i don't have anything in the list. How would i save this state... list1 has about 10 rows of 10 columns... i tried saving it in viewstate but page is showing error... plz provide help

    haseeb

    T S 2 Replies Last reply
    0
    • H haseeb_saeed

      Hi, I have a gridview (source is a list) which contains information that would be required to pull out more data from the database. actually, i wil be using that list when a btn is clicked to retrieve more information and then assign this second list to the gridview... ie 1 grid and two sources but source 2 is dependent on source1. i am using asp.net so with button click , state is lost and i don't have anything in the list. How would i save this state... list1 has about 10 rows of 10 columns... i tried saving it in viewstate but page is showing error... plz provide help

      haseeb

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

      When you need the data in your gridview, write a method SaveGridView to datatable. Then you can work with that datatable and use it to create datasource2. I have a method like that in one of my applications, which I will post as an example. My example uses template fields in the grid, but you can work with datafields as well. Not once you call the saveGridToDataTable you can rebind the grid to the table you just created.

      private DataTable saveGridToDataTable()
          {
              DataTable tbl = AppData.getEmptyOQTraineesTable();
              int testScore = 0;
      
              foreach (GridViewRow row in this.gvResults.Rows)
              {
                  if (row.Visible)
                  {
                      DataRow r = tbl.NewRow();
                      DateTime dValue = DateTime.Today;
                      TextBox txtTestDate = (TextBox)row.FindControl("txtTestDate");
                      TextBox txtQaulificationDate = (TextBox)row.FindControl("txtQualificationDate");
                      TextBox txtScore = (TextBox)row.FindControl("txtScore");
                      TextBox txtEmpNumber = (TextBox)row.FindControl("txtEmpNumber");
      
                      if (string.IsNullOrEmpty(txtEmpNumber.Text))
                          r\["Employee"\] = DBNull.Value;
                      else
                          r\["Employee"\] = txtEmpNumber.Text;
      
      
                      if (int.TryParse(txtScore.Text, out testScore))
                          r\["TestScore"\] = testScore;
      
                      if (DateTime.TryParse(txtTestDate.Text, out dValue))
                          r\["TaskDate"\] = dValue;
      
                      if (DateTime.TryParse(txtQaulificationDate.Text, out dValue))
                          r\["QualificationDate"\] = dValue;
      
                      tbl.Rows.Add(r);
                  }
              }
              return tbl;
          }
      

      public static DataTable getEmptyOQTraineesTable()
      {
      string x = string.Empty;
      DateTime y = DateTime.Today;
      Int32 z = 0;

              DataColumn dc1 = new DataColumn();
              dc1.DataType = x.GetType();
              dc1.ColumnName = "Employee";
      
              DataColumn dc3 = new DataColumn();
              dc3.DataType = y.GetType();
              dc3.ColumnName = "TaskDate";
      
      
              DataColumn dc4 = new DataColumn();
              dc4.DataType = z.GetType();
              dc4.ColumnName = "TestScore";
      
              DataColumn dc5 = new DataColumn();
              dc5.DataType = y.GetType();
      
      1 Reply Last reply
      0
      • H haseeb_saeed

        Hi, I have a gridview (source is a list) which contains information that would be required to pull out more data from the database. actually, i wil be using that list when a btn is clicked to retrieve more information and then assign this second list to the gridview... ie 1 grid and two sources but source 2 is dependent on source1. i am using asp.net so with button click , state is lost and i don't have anything in the list. How would i save this state... list1 has about 10 rows of 10 columns... i tried saving it in viewstate but page is showing error... plz provide help

        haseeb

        S Offline
        S Offline
        SayreCC
        wrote on last edited by
        #3

        Hi, Can you pls post your error? Thanks

        H 1 Reply Last reply
        0
        • S SayreCC

          Hi, Can you pls post your error? Thanks

          H Offline
          H Offline
          haseeb_saeed
          wrote on last edited by
          #4

          Hi, i don't get any compile time or runtime errors. i have to get values from table1 and then according to data of table 1, get table2 data using a button... i get data for table1 but when i click the btn, because http is stateless, i lose all the data that was in grid1... I need to maintain that data as state,so that in postback, i take out the data, do the searching and show table 2.... because table1 has alot of information, i don't know whether to save it in session,cookie or cache... also the data will change with each session, maybe 1 user will be checking one portion of table1 , other will be checking another portion... so how do i maintain all this detail... Thanx...

          haseeb

          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