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. page containing datatable has to be built and rebuilt again and again

page containing datatable has to be built and rebuilt again and again

Scheduled Pinned Locked Moved ASP.NET
help
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.
  • F Offline
    F Offline
    Flavia A
    wrote on last edited by
    #1

    hello, I have a gridview in a webpage where i use a datatable to populate the gridview,but only if the website is built and rebuilt the webpage works properly without exceptions,as the datatable does not retain any data that has been asign to it on the button click. Following is the code,

    static DataTable dtvalues = new DataTable();
    public static IICDServices icdObj;
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {

        }
    
    }
    
    private void Createdatatable()
    {
        dtvalues.Columns.Add("DL\_No");
        dtvalues.Columns.Add("F\_Name");
        dtvalues.Columns.Add("M\_Name");
        dtvalues.Columns.Add("L\_Name");
        dtvalues.Columns.Add("Unit");
        dtvalues.Columns.Add("Birth\_Date");
        dtvalues.Columns.Add("Mobile\_No");
        
    }
    

    //on the add button click i want all data from the textboxes to be assigned to the datatable.
    for which i have written the following code

    {

                        DataRow drvalues = dtvalues.NewRow();
                        drvalues\["DL\_No"\] = TxtDLNO.Text.ToUpper();
                        drvalues\["F\_Name"\] = txtFname.Text;
                        drvalues\["M\_Name"\] = txtMName.Text;
                        drvalues\["L\_Name"\] = txtLName.Text;
                        drvalues\["Unit"\] = ddlUnit.SelectedItem.Text;
                        drvalues\["Birth\_Date"\] = Gmdatepicker3.Date;
                        drvalues\["Mobile\_No"\] = TxtMobileNo.Text;
                        dtvalues.Rows.Add(drvalues);
                        GridView1.DataSource = dtvalues;
                        GridView1.DataBind();
                        TxtDLNO.Text = "";
                        txtFname.Text = "";
                        txtMName.Text = "";
                        txtLName.Text = "";
                        TxtMobileNo.Text = "";
                    }
    

    on the submit button click i want to redirect this page back to itself but it throws an exception as the page has npt been rebuilt.
    please help me out with this.
    thanks.

    A 1 Reply Last reply
    0
    • F Flavia A

      hello, I have a gridview in a webpage where i use a datatable to populate the gridview,but only if the website is built and rebuilt the webpage works properly without exceptions,as the datatable does not retain any data that has been asign to it on the button click. Following is the code,

      static DataTable dtvalues = new DataTable();
      public static IICDServices icdObj;
      protected void Page_Load(object sender, EventArgs e)
      {
      if (!IsPostBack)
      {

          }
      
      }
      
      private void Createdatatable()
      {
          dtvalues.Columns.Add("DL\_No");
          dtvalues.Columns.Add("F\_Name");
          dtvalues.Columns.Add("M\_Name");
          dtvalues.Columns.Add("L\_Name");
          dtvalues.Columns.Add("Unit");
          dtvalues.Columns.Add("Birth\_Date");
          dtvalues.Columns.Add("Mobile\_No");
          
      }
      

      //on the add button click i want all data from the textboxes to be assigned to the datatable.
      for which i have written the following code

      {

                          DataRow drvalues = dtvalues.NewRow();
                          drvalues\["DL\_No"\] = TxtDLNO.Text.ToUpper();
                          drvalues\["F\_Name"\] = txtFname.Text;
                          drvalues\["M\_Name"\] = txtMName.Text;
                          drvalues\["L\_Name"\] = txtLName.Text;
                          drvalues\["Unit"\] = ddlUnit.SelectedItem.Text;
                          drvalues\["Birth\_Date"\] = Gmdatepicker3.Date;
                          drvalues\["Mobile\_No"\] = TxtMobileNo.Text;
                          dtvalues.Rows.Add(drvalues);
                          GridView1.DataSource = dtvalues;
                          GridView1.DataBind();
                          TxtDLNO.Text = "";
                          txtFname.Text = "";
                          txtMName.Text = "";
                          txtLName.Text = "";
                          TxtMobileNo.Text = "";
                      }
      

      on the submit button click i want to redirect this page back to itself but it throws an exception as the page has npt been rebuilt.
      please help me out with this.
      thanks.

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      So you want to page should maintain the data after button click or what ?

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

      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