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. find runtime textbox value from grid

find runtime textbox value from grid

Scheduled Pinned Locked Moved ASP.NET
csshelptutorial
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.
  • S Offline
    S Offline
    Sneha Bisht
    wrote on last edited by
    #1

    I create a gridview with runtime columns. after that add textbox in this column. Here the code. protected void grdOne_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { TemplateField T = new TemplateField(); grdOne.Columns.Add(T); GridViewRow gvr = e.Row; TableCell tcell = new TableCell(); for (Int32 i = 0; i < columnCounter; i++) { TextBox tb = new TextBox(); tb.Width = 30; tb.Text = "0"; tb.ID = "tb_" + i.ToString(); tcell.Controls.Add(tb); } gvr.Cells.Add(tcell); grdOne.Controls[0].Controls.AddAt(0, gvr); } } But when i fetch textbox value from this grid that comes with error. can any one tell me how to fetch textbox value from my grid m using these line of code to fetch textbox values public void GetArray(GridView grd) { String[,] ar = new String[rowCounter, columnCounter]; for (int i = 0; i < grd.Rows.Count; i++) { for( int j=1; j<= grd.Columns.Count; j++) { String tId = "grdOne_ctl03_tb_" + j.ToString(); String t = ((DataControlFieldCell)(grd.Rows[i].FindControl()).text; } } }

    P 1 Reply Last reply
    0
    • S Sneha Bisht

      I create a gridview with runtime columns. after that add textbox in this column. Here the code. protected void grdOne_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { TemplateField T = new TemplateField(); grdOne.Columns.Add(T); GridViewRow gvr = e.Row; TableCell tcell = new TableCell(); for (Int32 i = 0; i < columnCounter; i++) { TextBox tb = new TextBox(); tb.Width = 30; tb.Text = "0"; tb.ID = "tb_" + i.ToString(); tcell.Controls.Add(tb); } gvr.Cells.Add(tcell); grdOne.Controls[0].Controls.AddAt(0, gvr); } } But when i fetch textbox value from this grid that comes with error. can any one tell me how to fetch textbox value from my grid m using these line of code to fetch textbox values public void GetArray(GridView grd) { String[,] ar = new String[rowCounter, columnCounter]; for (int i = 0; i < grd.Rows.Count; i++) { for( int j=1; j<= grd.Columns.Count; j++) { String tId = "grdOne_ctl03_tb_" + j.ToString(); String t = ((DataControlFieldCell)(grd.Rows[i].FindControl()).text; } } }

      P Offline
      P Offline
      Parwej Ahamad
      wrote on last edited by
      #2

      Something issue with control Id, it's not able to find the exact control id. It may be issue with control hierarchy. I have some suggestion for you: 1. If you want to follow the same code then view the page source and see what is name of control id and under which parent control has created. 2. Other way, Create a template column at design time and put there a panel. On runtime find the panel and add the all textbox control inside the panel. same way, during retrieval find the Panel and traverse the all child control. Thanks,

      Parwej Ahamad ahamad.parwej@gmail.com

      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