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. addin to gridview dynamically

addin to gridview dynamically

Scheduled Pinned Locked Moved ASP.NET
helpquestion
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.
  • T Offline
    T Offline
    the exile
    wrote on last edited by
    #1

    hi everybody my problem with gridview I create gridview like this //...................................

    //............................................. and in the below I have tow textbox and add button I want when click on add button the value of the tow textbox adding/inserting into the gridview (I want to add more than one value) how can I make that and thanks

    R 1 Reply Last reply
    0
    • T the exile

      hi everybody my problem with gridview I create gridview like this //...................................

      //............................................. and in the below I have tow textbox and add button I want when click on add button the value of the tow textbox adding/inserting into the gridview (I want to add more than one value) how can I make that and thanks

      R Offline
      R Offline
      raju melveetilpurayil
      wrote on last edited by
      #2

      1:Add textbox items in dataTable 2:Save dataTable in Session 3:Set GridView datasource as dataTable from Session check this sample code

      protected void Button1_Click(object sender, EventArgs e)
      {
      DataTable dt;
      DataRow drow;
      if (Session["datatable"] == null)
      {
      dt = new DataTable();

              DataColumn dcol = new DataColumn("Column1", typeof(string));
              //adding column to datatable
              dt.Columns.Add(dcol);
              int rowcount = 0;
      
              drow = dt.NewRow();
              dt.Rows.Add(drow);
              dt.Rows\[rowcount\]\[dcol\] = TextBox1.Text;
              //add datatable to session
              Session.Add("datatable", dt);
          }
          else
          {
              dt = (DataTable)Session\["datatable"\];
              drow = dt.NewRow();
              dt.Rows.Add(drow);
              dt.Rows\[dt.Rows.Count-1\]\["Column1"\] = TextBox1.Text;
      
              //add datatable to session
              Session.Add("datatable", dt);
          }
              //bind gridview
              GridView1.DataSource = dt;
              GridView1.DataBind();
          
      }
      

      makhaai

      modified on Thursday, June 10, 2010 5:06 PM

      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